-
-
Notifications
You must be signed in to change notification settings - Fork 863
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
Variable marked as always defined, even though it might be unset
#6997
Comments
Ok, after a bit more digging, in 1.5.3 this code doesn't report: public function sayHello(array $foo): void
{
$whereParts = [];
if (!$foo['a']) {
$whereParts[] = 'something';
}
if (!$foo['b']) {
$count = 3;
// notice the 2 pushes to the array
$whereParts[] = 'example';
$whereParts[] = 'bar';
}
if (empty($whereParts)) {
return [];
}
return isset($count) ? $count : 0;
} but the original does |
@icatalina After the latest push in 1.8.x, PHPStan now reports different result with your code snippet: @@ @@
-22: Variable $count in isset() always exists and is not nullable.
+No errors |
👏 |
Ondrej most likely wants a regression test for it before closing it :) |
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
This seems like a regression from 1.5.3, we didn't have this issue before.$count
is marked as always defined, it can clearly beunset
.Code snippet that reproduces the problem
https://phpstan.org/r/81e9327a-136e-4a7f-908e-b571c173d32c
Expected output
No error
Did PHPStan help you today? Did it make you happy in any way?
80% of the time, it does all the time!
The text was updated successfully, but these errors were encountered: