-
-
Notifications
You must be signed in to change notification settings - Fork 864
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 assignment inside if-statement gives unexpected type #2413
Comments
Confirmed this is still an issue in 0.12. |
I stumbled upon the same issue with an |
@Cxarli PHPStan now reports different result with your code snippet: @@ @@
-25: Cannot access property $field on TestClass|null.
+No errors |
@Cxarli PHPStan now reports different result with your code snippet: @@ @@
-25: Cannot access property $field on TestClass|null.
+ 6: Property TestClass::$field has no typehint specified.
+12: Function getTest() has no return typehint specified.
+22: Function main() has no return typehint specified. Full report
|
That seems to fix it. Closed |
This issue isn't solved, it just moved to level 8: https://phpstan.org/r/c761685b-cc60-4d01-bbbd-c903d75453c2 |
@guilliamxavier After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-6: Parameter #1 $json of function json_decode expects string, string|false given.
+No errors |
@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-25: Cannot access property $field on TestClass|null.
+No errors |
Fixed: phpstan/phpstan-src@b2bf703 |
Closes phpstan/phpstan#4761 Closes phpstan/phpstan#3331 Closes phpstan/phpstan#3106 Closes phpstan/phpstan#2640 Closes phpstan/phpstan#2413 Closes phpstan/phpstan#3446
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
Version:
PHPStan - PHP Static Analysis Tool 0.11.x-dev@f6fed5f
(but also occurs on the web version)If you assign a variable inside an if-statement, it seems the type hinting derived from the rest of that if-statement is lost inside the actual clause.
Code snippet that reproduces the problem
https://phpstan.org/r/16f1a2ba-5624-4f82-b716-0544d7427594
Expected output
I didn't expect this warning to happen. If you place the assignment before the if-statement, everything is fine. The (private) code base I'm working on has this all over the place however, so it makes using phpstan a bit harder.
The text was updated successfully, but these errors were encountered: