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 undefined when defined in prior if
block
#1306
Comments
There is a potentially related issue here: https://phpstan.org/r/07a9e0d5cc770c25203bcc3bc3b9c9b1 <?php
function bar($foo = null) {
if ($foo !== null) {
$someBoolean = false;
}
if ($foo !== null && $someBoolean === false) {
}
} ------ ---------------------------------------------
Line analyzed.php
------ ---------------------------------------------
8 Variable $someBoolean might not be defined.
------ --------------------------------------------- In the above case |
Hi, this is hard to solve. There are other issues like this: https://github.com/phpstan/phpstan/milestone/12 I might tackle this one day, but it's not a priority. Meanwhile, you should always use |
ok thanks, no worries.
I think the above is valid (even if horrible - not my code 🙄 ) |
Yeah but I’m suggesting analyser-friendly code that will stop reporting
that error.
ne 29. 7. 2018 v 11:32 odesílatel dantleech <notifications@github.com>
napsal:
ok thanks, no worries.
Meanwhile, you should always use isset in the second condition.
I think the above is valid (even if horrible - not my code 🙄 )
$someBoolean will not be evaluated if the left side of the && is false.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1306 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAGZuEqLxlry2Ew8DxKBSKDCjDdIw0dDks5uLYE2gaJpZM4Vk7FK>
.
--
Ondřej Mirtes
|
+1 from me, I have also just run into this problem. Following thread. |
This is common for things that are only executed in debug mode; see https://phpstan.org/r/1df6d7d1-6a34-499d-93d1-eab18dcef390. Normally there would be other things between the two ifs, of course. |
Fixed: phpstan/phpstan-src@54284c8 |
phpstan/phpstan-src@1ce60e9 Regression test for #1306
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. |
Summary of a problem or a feature request
In the below example the two conditionals both evaluate to true based on the same variable. If the variable is true the code within each block should be evaluated and
$foo
should therefore be defined in the second block, but Phpstan reports that it might be undefinedCode snippet that reproduces the problem
https://phpstan.org/r/112e67a0d4bd81232da6a687b6605d42
The text was updated successfully, but these errors were encountered: