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
Not null affectation does not define variable #4662
Comments
Yeah, this is problematic, but you can work around this with arguably more readable code: https://phpstan.org/r/2fa5189a-4e20-4f7a-8cad-6f83c1fff0c7 |
Actually I was pretty sure it worked before, but I cannot make it work from v0.12.60. Maybe I just dreamt about it ;-) Thanks for hard work! |
@alterphp After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
+ 8: Property Foo::$programStartDate is never written, only read.
22: Undefined variable: $programStartDate Full report
|
@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-No errors
+8: Property Foo::$programStartDate is never written, only read. Full report
|
@alterphp After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
+ 8: Property Foo::$programStartDate is never written, only read.
22: Undefined variable: $programStartDate Full report
|
@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-No errors
+8: Property Foo::$programStartDate is never written, only read. Full report
|
Bug report
In a if statement, I first check that affectation of a variable is not NULL, and then try to use the variable in a second part of the condition. PHPStan output an error like
Undefined variable: $affectedVar
.It could be related to #4357.
Code snippet that reproduces the problem
https://phpstan.org/r/43c76836-a07b-40ef-826f-e72c889b9024
Expected output
In the above example, PHPStan should not output that
$programStartDate
is undefined at line 22.The text was updated successfully, but these errors were encountered: