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
Call to function array_key_exists() with int and array will always evaluate to true #3766
Comments
@ondrejmirtes Please help me find where the error is, which class look at |
@ossinkine Check what's I suspect it will be something like This error message comes from this class - https://github.com/phpstan/phpstan-src/blob/master/src/Rules/Comparison/ImpossibleCheckTypeHelper.php - if it returns true, it's always true, if it returns false, it's always false, if it returns null, nothing is reported. So you can see for yourself what types are compared with isSuperTypeOf in this branch https://github.com/phpstan/phpstan-src/blob/e96481c3210c9aa93de45f482c11789c1face65d/src/Rules/Comparison/ImpossibleCheckTypeHelper.php#L173-L195 and if the result of isSuperTypeOf between those types makes sense or not. |
@ondrejmirtes Unfortunatelly I could not figure out with this. The code you pointed is executed 5 times in my test,
As a result the array has any integer offset what should be wrong but I don't how to fix this. |
@ossinkine After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-14: Call to function array_key_exists() with int and array will always evaluate to true.
+No errors |
@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-15: Call to function array_key_exists() with int and array will always evaluate to true.
+No errors |
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. |
Bug report
False-positive alerts when using
array_key_exists
function.Code snippet that reproduces the problem
https://phpstan.org/r/ce4a9861-014d-4ccc-84db-0e8d9ab47e34
Expected output
Expecting no alerts
The text was updated successfully, but these errors were encountered: