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
/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.
in_array
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 #5355 when in_array is handled indirectly are also solved.
Thank you.
https://phpstan.org/r/179a9da2-e9e7-4d4b-b4af-b0e01c35a9db and many others
The text was updated successfully, but these errors were encountered:
I did something: phpstan/phpstan-src@4321374
But it's still a mess worthy of some deep research and cleanup.
Sorry, something went wrong.
@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet:
@@ @@ -15: Call to function in_array() with arguments 0, array<int, 0|1> and true will always evaluate to true. +No errors
Successfully merging a pull request may close this issue.
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_arrayis 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_arrayshould 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 #5355 whenin_arrayis 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
The text was updated successfully, but these errors were encountered: