You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the documentation for PHP 8.0 backward incompatibility, in the Standard Library section, there is no mention of the change in behavior for array_walk when the first argument passed to it is not of type array|object.
The following code behaves differently between PHP 7.4 and PHP 8.0:
$a = null;
array_walk($a, 'strtolower');
In PHP 7.4 the output is:
Warning: array_walk() expects parameter 1 to be array, null given in <FILENAME> on line <LINE>
In PHP 8.0+ the output is:
Fatal error: Uncaught TypeError: array_walk(): Argument #1 ($array) must be of type array, null given in <FILENAME>: <LINE>
We are currently upgrading our host environments and ran into this issue post-upgrade. Most everything else to look out for is in the documentation, but this one caught us off guard because there is no mention of it in the docs.
The text was updated successfully, but these errors were encountered:
This isn't just about array_walk: all(ish) built-in functions were changed to throw a TypeError when passed arguments with the wrong types. Which is how userland functions already worked. https://wiki.php.net/rfc/consistent_type_errors
I'm not seeing it documented in the migration guide though, which is kinda surprising...
We technically considered passing invalid types UB, and it has a noted somewhere. Probably the reason why we didn't document this in the migration guide.
In the documentation for PHP 8.0 backward incompatibility, in the Standard Library section, there is no mention of the change in behavior for
array_walk
when the first argument passed to it is not of typearray|object
.The following code behaves differently between PHP 7.4 and PHP 8.0:
In PHP 7.4 the output is:
In PHP 8.0+ the output is:
We are currently upgrading our host environments and ran into this issue post-upgrade. Most everything else to look out for is in the documentation, but this one caught us off guard because there is no mention of it in the docs.
The text was updated successfully, but these errors were encountered: