Skip to content

incorrect type narrowing triggered by ($a ?? null) === false #12057

@claudepache

Description

@claudepache

Bug report

After an early return of the form

if (($options['foo'] ?? null) === false)
     return;

PHPStan has incorrectly narrowed $options['foo'] to existing and non-nullable.

Code snippet that reproduces the problem

https://phpstan.org/r/573ad351-ccf3-45b6-9fb6-16a5a9fa149d

Expected output

Dumped type: array{foo?: mixed~false}

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

Yes, except that it leads me to correct bugs in code that will never be run anyway

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions