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

False positive "will always evaluate to false" after array_filter and reset #7928

Closed
rieschl opened this issue Sep 4, 2022 · 2 comments · Fixed by phpstan/phpstan-src#1696

Comments

@rieschl
Copy link

rieschl commented Sep 4, 2022

Bug report

When an array with possible null values is filtered with array_filter and then the first entry is fetched with reset, PHPStan thinks that the array cannot be empty and will emit an error on a === false check.

I tried it on version 1.8.4. 1.8.3 outputs the same error, but 1.8.2 does not.
PHP version 7.4.30

Code snippet that reproduces the problem

https://phpstan.org/r/808dcfd1-17d2-4a54-8cf7-defb3d90dbb1

Expected output

PHPStan should not output an error because reset indeed can return false.

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

PHPStan helps me every time I write some code because it reminds me that there are things to consider I didn't think about 🙂

@rieschl
Copy link
Author

rieschl commented Sep 5, 2022

Thanks for the quick fix!

@github-actions
Copy link

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

Successfully merging a pull request may close this issue.

1 participant