Skip to content

Variable marked as always defined, even though it might be unset #6997

@icatalina

Description

@icatalina

Bug report

This seems like a regression from 1.5.3, we didn't have this issue before.

$whereParts = [];

if (!$foo['a']) {
    $whereParts[] = 'something';
}

if (!$foo['b']) {
    $count = 3;
    $whereParts[] = 'example';
}

if (empty($whereParts)) {
    return [];
}

return isset($count) ? $count : 0;

$count is marked as always defined, it can clearly be unset.

Code snippet that reproduces the problem

https://phpstan.org/r/81e9327a-136e-4a7f-908e-b571c173d32c

Expected output

No error

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

80% of the time, it does all the time!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions