-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for php7.4: Trying to access array offset on value of type int #145
base: master
Are you sure you want to change the base?
Conversation
src/Unirest/Request.php
Outdated
if (!is_string($port)) { | ||
$port = strval($port); | ||
} | ||
if ($port[0] !== ':') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As strval() returns the unmodified string if you put a string into it, you might consider simplifying the code to
if ($port && strval($port)[0] !== ':') {
$port = ':' . $port;
}
In my opinion, this would be easier to read and gave a better impression of what the code is doing.
Also, if $port is ''
(empty string), it will get through the type safe not null check and this will call an undefined index on $port. This is just a notice in PHP, however, it won't occur with a weak null check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just updated it, what do you think about this version ? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! 👍
Thanks for the fix. Would be awesome if this PR can be merged so we can use it without the workaround! The build error seems to be related to the build environment and not so much about this PR. |
Can we get this PR merged so we don't have to use the workaround? |
Clément Lovergne seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
This shoudl fix #143