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 misses "always false" when using in_array unless strict mode is enabled #4238

Closed
pontus-mp opened this issue Dec 15, 2020 · 5 comments

Comments

@pontus-mp
Copy link

Bug report

PHPstan doesn't notice when in_array always returns false, unless strict rules are enabled. This might be related to #2870.

Code snippet that reproduces the problem

https://phpstan.org/r/4129c443-3a90-4dd3-b5e3-2d1d2944eafe

Expected output

9 | Call to function in_array() with arguments 'first'|'second', array('first', 'second') and true will always evaluate to true.

@ondrejmirtes
Copy link
Member

This is expected, it's actually "always true" situation.

@ondrejmirtes
Copy link
Member

You can turn it on even without strict-rules installed: https://phpstan.org/config-reference#checkalwaystruechecktypefunctioncall

@pontus-mp
Copy link
Author

That only seems to have an effect if the third (strict) parameter is true. PHPStan fails to find an issue in this snippet when checkAlwaysTrueCheckTypeFunctionCall is enabled, unless the third parameter is set to true.

https://phpstan.org/r/be7c6ec9-34e0-4d2f-8583-03162b90b7dd

@ondrejmirtes
Copy link
Member

ondrejmirtes commented Dec 15, 2020

Yes, because loose comparison is really complicated and basically any type can equal to any type, given the right value. For example ('0' == false)...

@github-actions
Copy link

github-actions bot commented May 4, 2021

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 May 4, 2021
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