Skip to content

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

Open
@will621

Description

@will621

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions