php-imageoptim-api icon indicating copy to clipboard operation
php-imageoptim-api copied to clipboard

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

Open will621 opened this issue 3 years ago • 0 comments

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.

will621 avatar Apr 29 '22 13:04 will621