Skip to content

Variable undefined when defined in prior if block #1306

@dantleech

Description

@dantleech

Summary of a problem or a feature request

In the below example the two conditionals both evaluate to true based on the same variable. If the variable is true the code within each block should be evaluated and $foo should therefore be defined in the second block, but Phpstan reports that it might be undefined

 ------ ------------------------------------- 
  Line   analyzed.php                         
 ------ ------------------------------------- 
  4      ... 
  10     ...
  11     Variable $foo might not be defined.  
 ------ ------------------------------------- 

Code snippet that reproduces the problem

            <?php

            $baz = true; // ignore: could be false|true at runtime
            if ($baz) {
                $foo = 'asd';
            }

            if ($baz) {
                $bar = $foo; 
            }

https://phpstan.org/r/112e67a0d4bd81232da6a687b6605d42

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions