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

Php 7.4 exception: "Trying to access array offset on value of type int" #6

Open
will621 opened this issue Apr 29, 2022 · 0 comments
Open

Comments

@will621
Copy link

will621 commented Apr 29, 2022

In the process of upgrading php from 7.1 to 7.4 for the app using this library and it looks like 7.4 is a bit more strict with certain things and is causing the following code (line 2) to throw an exception "Trying to access array offset on value of type int" and fail.

https://github.com/ImageOptim/php-imageoptim-api/blob/master/src/Request.php#L163
$status = intval($status[1]);
$errorMessage = $status[2];
I think the issue is that the first line is setting $status to an int, and then trying to treat it like an array in the next line, which PHP 7.4 now throws and exception for (before it would just be null and carry on)

https://www.php.net/manual/en/migration74.incompatible.php
"Array-style access of non-arrays
Trying to use values of type null, bool, int, float or resource as an array (such as $null["key"]) will now generate a notice."

Possible simple fix at the moment is just to swap the two lines around.

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

No branches or pull requests

1 participant