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

PHPStan does not detect that shuffle() reindexes array keys #6138

Closed
johnbillion opened this issue Dec 2, 2021 · 4 comments · Fixed by phpstan/phpstan-src#1438
Closed

PHPStan does not detect that shuffle() reindexes array keys #6138

johnbillion opened this issue Dec 2, 2021 · 4 comments · Fixed by phpstan/phpstan-src#1438
Labels
Milestone

Comments

@johnbillion
Copy link
Contributor

Bug report

When an array is passed to shuffle() it gets reindexed from 0. PHPStan does not detect this.

Code snippet that reproduces the problem

Expected output

shuffle() should be aware that the array that's passed to it gets reindexed from 0.

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

Always :)

@johnbillion johnbillion changed the title shuffle() does not reindex array keys PHPStan does not detect that shuffle() reindexes array keys Dec 2, 2021
@staabm
Copy link
Contributor

staabm commented Dec 2, 2021

Feel free to implement a Dynamic Return Type extension for shuffle

https://phpstan.org/developing-extensions/dynamic-return-type-extensions

@ondrejmirtes
Copy link
Member

AFAIK shuffle() doesn't return the shuffled array, but changes it in-place. The extension isn't applicable here, instead it needs to be hardcoded in NodeScopeResolver.

@johnbillion
Copy link
Contributor Author

Correct, it's one of the array functions that operates directly on the array passed by reference.

@github-actions
Copy link

github-actions bot commented Aug 2, 2022

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 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants