-
-
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
Missed change of variable type in foreach #4907
Comments
Just use a different variable name for the value 🤣 |
Yes, this is easy fix in code. :) But when reviewer and test fails and miss this issue it will cause TypeError. Maybe it could be check with some codestyle check not only with PHPStan.. 🤔 |
Yes, with strict-rules this is checked 😊 https://phpstan.org/r/04b78bc7-dd20-4a1d-8cc4-47e4cffbc530 |
Thanks, strict-rules are good solution. 👍 This is not a bug for me. Let's close this issue? Or are you interested in adding this check into some PHPStan level? |
PHPStan should correctly know what's there: https://phpstan.org/r/79e304ca-c2f1-4b07-bc79-f4d724f5ed59 Right now it fails for some reason. |
@integer After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-No errors
+17: Function bar() should return array<int> but return statement is missing. Full report
|
@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
- 6: Foreach overwrites $foo with its value variable.
+17: Function bar() should return array<int> but return statement is missing. Full report
|
@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-10: Dumped type: *ERROR*
+No errors |
@integer After the latest push in 1.11.x, PHPStan now reports different result with your code snippet: @@ @@
-No errors
+10: Parameter #1 $x of function bar expects array<int>, int given. Full report
|
@ondrejmirtes After the latest push in 1.11.x, PHPStan now reports different result with your code snippet: @@ @@
- 6: Foreach overwrites $foo with its value variable.
+ 6: Foreach overwrites $foo with its value variable.
+10: Parameter #1 $x of function bar expects array<int>, int given. Full report
|
@ondrejmirtes After the latest push in 1.11.x, PHPStan now reports different result with your code snippet: @@ @@
-10: Dumped type: *ERROR*
+10: Dumped type: 5|6|7 Full report
|
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
You iterate an array and overrides variable outside cycle. PHPStan not update variable type and expecting different type than real PHP runtime. Code falls with TypeError
Code snippet that reproduces the problem
Same code here: https://phpstan.org/r/9743d6e1-0f56-4748-a50d-a61a0d79e6c2
Expected output
Parameter #1 $x of function bar expects array, int given.
The text was updated successfully, but these errors were encountered: