Skip to content
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

False positive about possibly undefined variable after for loop #195

Closed
greg0ire opened this issue Dec 1, 2022 · 3 comments
Closed

False positive about possibly undefined variable after for loop #195

greg0ire opened this issue Dec 1, 2022 · 3 comments

Comments

@greg0ire
Copy link

greg0ire commented Dec 1, 2022

Bug report

With strict rules turned on PHPStan reports that a variable will always be overwritten if followed by a for loop that uses it in the assignment part, and that's great: https://phpstan.org/r/244ed1d0-003c-492f-99d2-ce5a075ae515

If you attempt to fix that though, you run into a contradictory error:

Code snippet that reproduces the problem

https://phpstan.org/r/030872ba-acba-4a27-b267-1f30156b1417

Expected output

No errors

Did PHPStan help you today? Did it make you happy in any way?

Yes, it helps me make it easier to spot errors in data providers

@MartinMystikJonas
Copy link
Contributor

MartinMystikJonas commented Dec 1, 2022

This is expected. Strict rules disallow use of variables from loops outside loops. You can turn off this behaviour (enabled by strict rules) by this config option https://phpstan.org/config-reference#pollutescopewithloopinitialassignments to false true (edited)

@greg0ire greg0ire closed this as completed Dec 1, 2022
@greg0ire
Copy link
Author

greg0ire commented Dec 1, 2022

Thanks @MartinMystikJonas !

@github-actions
Copy link

github-actions bot commented Jan 2, 2023

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants