-
-
Notifications
You must be signed in to change notification settings - Fork 933
Description
Bug report
/cc @herndlm this is something up your alley, could you please spare a few days to occupy your mind with this to see how it could be solved? :)
in_array is a very problematic function - the type-specifying extension (https://github.com/phpstan/phpstan-src/blob/master/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php) currently serves to narrow down the type of the first argument.
The problems come when the error "Call to function in_array() will always evaluate to true/false" is reported for cases where it's not correct.
Here are some open issues about it: https://github.com/phpstan/phpstan/issues?q=is%3Aissue+is%3Aopen+in_array
Please note that this should be solved entirely with conditions in the type-specifying extension and the code related to in_array should be removed from https://github.com/phpstan/phpstan-src/blob/bedcc2db8616d195f4cf698d3731cc69d634c2b7/src/Rules/Comparison/ImpossibleCheckTypeHelper.php#L81-L130 entirely. This is so that issues like this phpstan/phpstan-webmozart-assert#142 when in_array is handled indirectly are also solved.
Thank you.
Code snippet that reproduces the problem
https://phpstan.org/r/179a9da2-e9e7-4d4b-b4af-b0e01c35a9db and many others