phpstan: False positive always-true with `in_array`
I expect no error from the code https://phpstan.org/r/179a9da2-e9e7-4d4b-b4af-b0e01c35a9db
In my project issue I get
Call to function in_array() with arguments 0, array<int, 0|1>&nonEmpty and true will always evaluate to true.
But even if the array is non-empty, the in_array check isn’t supposed to be always true.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 15 (13 by maintainers)
The issue can be simplified to https://phpstan.org/r/02705e4a-3f03-4fa4-83c1-9e1ec86a76f5
array<int, 0|1>doesn’t always contain0to me.[1, 1, 1, 1]or[]are both example which are compatible to thearray<int, 0|1>definition to me.in_array()is a problematic function. Here’s where it’s implemented:Ideally all of this should be handled in InArrayFunctionTypeSpecifyingExtension. It would also fix https://github.com/phpstan/phpstan-webmozart-assert/issues/142.