-
Notifications
You must be signed in to change notification settings - Fork 784
ForEach does not issue an error for non-iterable non-Traversable objects #4534
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
Comments
Notably, if the implementation is changed to match the documentation, it would break a lot of code in the wild.. (unless we make all objects implement traversable by default, that would be a BC-compatible way of fixing it, but that would make the traversable interface pointless, I think) |
All objects are iterable by default (not in the iterator api sense, but in that foreach accepts them). This is legacy behavior and cannot easily be removed. The documentation could be clearer though. Moving this to the appropriate repository. |
it's not just unclear, it's wrong. if it changed to
it would be correct. or
would also be correct.
is wrong. |
Description
The following code:
Resulted in this output:
But given the ForEach documentation, I expected this output instead:
(some variant of that)
So it seems either the documentation or the implementation is wrong here.
PHP Version
PHP 8.4.5
Operating System
Ubuntu24.04
The text was updated successfully, but these errors were encountered: