Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

loverg-c
Copy link

This shoudl fix #143

if (!is_string($port)) {
$port = strval($port);
}
if ($port[0] !== ':') {
Copy link

@janopae janopae Mar 6, 2020

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
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

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

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
Copy link

allansun commented Sep 4, 2020

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

@CLAassistant
Copy link

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