Skip to content

Fix for php7.4: Trying to access array offset on value of type int#145

Open
loverg-c wants to merge 3 commits into
Kong:masterfrom
loverg-c:master
Open

Fix for php7.4: Trying to access array offset on value of type int#145
loverg-c wants to merge 3 commits into
Kong:masterfrom
loverg-c:master

Conversation

@loverg-c

Copy link
Copy Markdown

This shoudl fix #143

Comment thread src/Unirest/Request.php Outdated
if (!is_string($port)) {
$port = strval($port);
}
if ($port[0] !== ':') {

@janopae janopae Mar 6, 2020

Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Author

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 ? :)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 👍

thehappybug added a commit to apimatic/unirest-php that referenced this pull request Apr 7, 2020
@denniswiemer

Copy link
Copy Markdown

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.

@allansun

allansun commented Sep 4, 2020

Copy link
Copy Markdown

Can we get this PR merged so we don't have to use the workaround?

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trying to access array offset on value of type int

5 participants