Skip to content

False-positive nullCoalesce.property when combined with array access #14555

@shira-374

Description

@shira-374

Bug report

Getting a nullCoalesce.property error on statements like these, where $array is array<string, list<SomeDTO>>:

$value = $array['foo'][0]->value->value ?? null;

The 'foo' and 0 offsets might not exist, so the ?? usage is valid and should not be reported. The fact that ValueObject::$value is not nullable is not relevant in this case.

This seems to only happen when chained property accesses are involved. Statements like $array['someKey'][0]->value ?? null don't produce this false-positive.

Code snippet that reproduces the problem

https://phpstan.org/r/e60e7f65-17e5-41e8-b070-3d56d2d65946

Expected output

No error

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

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions