-
-
Notifications
You must be signed in to change notification settings - Fork 887
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
Refinement of key existence is wrong when using a AND in a condition #7224
Comments
/cc @rajyan Sounds like something for you :) |
The problem is explained here phpstan/phpstan-src#1307 (comment) The isset reverNonNullability process is not working for optional keys now, so simply calling a no effect isset call can causes the same issue. |
@stof After the latest push in 1.8.x, PHPStan now reports different result with your code snippet: @@ @@
7: Dumped type: array{id: string, name?: string, team_name?: string|null}
-12: Dumped type: array{id: string, name?: string, team_name: string|null}
-16: Call to function array_key_exists() with 'team_name' and array{id: string, name?: string, team_name: string|null} will always evaluate to true.
+12: Dumped type: array{id: string, name?: string, team_name?: string|null} Full report
|
@rajyan After the latest push in 1.8.x, PHPStan now reports different result with your code snippet: @@ @@
7: Dumped type: array{id: string, name?: string, team_name?: string|null}
-12: Dumped type: array{id: string, name?: string, team_name: string|null}
-16: Call to function array_key_exists() with 'team_name' and array{id: string, name?: string, team_name: string|null} will always evaluate to true.
+12: Dumped type: array{id: string, name?: string, team_name?: string|null} Full report
|
@rajyan This is how I fixed revertNonNullability :) phpstan/phpstan-src@0654852?w=1 The issue was that |
@ondrejmirtes |
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
When using
if (!isset($a['first_key']) && !isset($a['second_key'])) return;
, phpstan refinesfirst_key
as not being optional in the array shape of$a
after the early returnCode snippet that reproduces the problem
https://phpstan.org/r/292eadfe-27e6-4668-b7e5-ccc91c581290
Expected output
The
array_key_exists
call is not reported as useless by strict rules, becauseteam_name
can indeed be missing when reaching it.Did PHPStan help you today? Did it make you happy in any way?
The text was updated successfully, but these errors were encountered: