Skip to content

array_pop(): Unreachable statement - code above always terminates. #3875

@mahagr

Description

@mahagr

Bug report (version 0.12.42)

If you have a queue with single item in it, phpstan seems to think that array_pop() returns null.

Code snippet that reproduces the problem

https://phpstan.org/r/57010e6f-71f7-4b56-9e14-e6b55b87cf47

function foo(): void
{
    $queue = ['asd'];
    $list = [];
    do {
        $current = array_pop($queue);
        if ($current === null) {
            break;
        }

        $list[] = $current;
    } while ($queue);
}

Output

Line 10: Unreachable statement - code above always terminates.

Expected output

No error

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions