Replies: 1 comment 1 reply
-
The playground tells you: Template type TValue on class ArrayIterator is not covariant. Learn more: What's Up With @template-covariant? The article explains that. You can cast the returned type though: https://phpstan.org/r/c1d8b1db-e5db-4105-bef0-b586943350fa |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I can't really explain this behavior to a colleague, so I figured someone might offer some insight.
We have a piece of code (test, actually) that is supposed to create a dummy
Traversable
object. We figured we will narrow down the return type (Iterator
->ArrayIterator
) and so we also added the annotation indicating that we are interested inarray<int>
as results.However, PHPStan reports
array{int,int,int,int}|array{int}
as incompatible, which raised our eyebrows.Why does it happen? 🤔
https://phpstan.org/r/673467b9-520d-4290-98c8-9ca5e9d76ef5
Error reported:
Beta Was this translation helpful? Give feedback.
All reactions