Skip to content

switch(true) & always true conditions reports possibly undefined variable #2003

@kiler129

Description

@kiler129

Summary of a problem or a feature request

The following code:

<?php declare(strict_types = 1);

function foo(array $list)
{
    foreach ($list as $part) {
        switch (true) {
            case isset($list['magic']):
                $key = 'to-success';
                break;

            default:
                continue 2;
        }

        echo $key;
    }
}

Causes PhpStan to think that Variable $key might not be defined., which I see no way to be true.
It seems like there's a problem with continue 2 handling.

Code snippet that reproduces the problem

https://phpstan.org/r/db60d610-b3cf-40f3-ad51-8deb9a5c9f73

Expected output

No errors should be reported

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions