Skip to content

Conditionally defined variables flagged as undefined #8212

@ksours

Description

@ksours

Bug report

This is the example of conditionally defined variables from:
https://phpstan.org/writing-php-code/solving-undefined-variables

Despite the documentation saying that PHPStan understands this case, it doesn't actually appear to. The snippet itself has the problem that $foo is undefined but if it's set to a indeterminate value than $var will be flagged as undefined (if the level is at least 1). Note that if $foo is determined to be truthy then no error is produced.

Code snippet that reproduces the problem

https://phpstan.org/r/b720c0fb-d944-4ba4-9d9b-a0b3c81f55c1

Expected output

Expect that this is not flagged because var is defined any time it is not referenced.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions