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

Undocumented change to error behavior in array_walk from PHP 7.4 to PHP 8.0 #2509

Closed
RobertGonzalez opened this issue Jun 2, 2023 · 3 comments

Comments

@RobertGonzalez
Copy link

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.

@damianwadley
Copy link
Member

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

@Girgias
Copy link
Member

Girgias commented Jun 2, 2023

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.

@Girgias
Copy link
Member

Girgias commented Jul 25, 2023

As said previously we consider this UB, and it is something that is generally documented in the internal functions documentation

@Girgias Girgias closed this as not planned Won't fix, can't repro, duplicate, stale Jul 25, 2023
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

3 participants