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

Check BooleanInCondition for while and for loop #259

Open
VincentLanglet opened this issue Jan 22, 2025 · 1 comment · May be fixed by #260
Open

Check BooleanInCondition for while and for loop #259

VincentLanglet opened this issue Jan 22, 2025 · 1 comment · May be fixed by #260

Comments

@VincentLanglet
Copy link
Contributor

See https://phpstan.org/r/2930c63b-1ea1-4711-9272-a4de8f998a82

In the while loop, 0 and null are treated the same way, which might create bugs (in the same way it can occur for if condition).

Same idea for the for loop condition $j which might be a typo, missing the real condition.

WDYT about extending the BooleanInCondition to while and for loop @ondrejmirtes ?

I dunno it the for loop need to allow empty expression like

for ($i = 1; ; $i++) {
    if ($i > 10) {
        break;
    }
    echo $i;
}
@ondrejmirtes
Copy link
Member

Yeah, sure, makes sense. There are more blindspots:

  • while
  • do-while
  • for

We might be able to find more by searching for $cond in PHP-Parser.

@VincentLanglet VincentLanglet linked a pull request Jan 22, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants