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

A SplFixedArray is not interpreted as iterable. #11269

Closed
PedroTroller opened this issue Jul 2, 2024 · 4 comments
Closed

A SplFixedArray is not interpreted as iterable. #11269

PedroTroller opened this issue Jul 2, 2024 · 4 comments

Comments

@PedroTroller
Copy link

PedroTroller commented Jul 2, 2024

Bug report

Hello !

I use a SplFixedArray which contains a value of type T. I pass this SplFixedArray as a parameter to a function that expects a iterable<T>, and phpstan returns an error.

Code snippet that reproduces the problem

https://phpstan.org/r/5c3cd16c-89d1-4734-b329-0fcce1f48b79

Expected output

SplFixedArray<T> implements IteratorAggregate<T> which extends Traversable<T> which is then a, iterable<T>. So logically it should work.... Unless I'm wrong somewhere 😄

Did PHPStan help you today? Did it make you happy in any way?

Thank you for this great product. You make all our work much more qualitative and our applications more stable... Thank you thank you thank you thank you...

@ondrejmirtes
Copy link
Member

That's because SplFixedArray<int> is Iterator<int|null>. See the stub here: https://github.com/phpstan/phpstan-src/blob/25658f64f0bcfe784893104864d92032cce33e96/stubs/ArrayObject.stub#L89-L108

Fixed example: https://phpstan.org/r/13d3ae1e-6356-4c15-b948-d04ffa08bfbf

@ondrejmirtes
Copy link
Member

Here's when it changed: phpstan/phpstan-src#587

@PedroTroller
Copy link
Author

Thanks a lot !

Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants