Skip to content

False positive "variable might not be defined" inside for loop #10657

@t-gebauer

Description

@t-gebauer

Bug report

Combining dependent types with a for loop causes PHPStan to falsely report an error.

In the linked code, $foo is guaranteed to be defined, when $flag is truthy.

Code snippet that reproduces the problem

https://phpstan.org/r/79ccd56f-c164-4389-8ed4-2e593b350449

Expected output

PHPStan should not report an error. Just like the same code without a loop: https://phpstan.org/r/45d91429-2383-4127-9f84-6b3e96eaa9be

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

Yes, every other day it finds possible bugs :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions