Skip to content

Null coalescing operator throwing access property error #3171

@Krunch

Description

@Krunch

Bug report

Code snippet that reproduces the problem

https://phpstan.org/r/c03dea3a-c5d2-4fa7-85e5-2e58f5f43cd1

Error message:
Cannot access property $someArray on PropertyClass|null.

Expected output

No phpstan error. Null coalesce already properly handles nested nulls, and array access to missing keys properly. There is no ambiguity in the code, no dynamic properties are being used so this should be properly handled by phpstan.

Interesting note: If you remove |null from the @var notation then no phpstan error is thrown. It seems to be only triggered when $property can also be null.

Also, if $someArray happened to be something other than an array (like string|null) it would also properly work and phpstan would throw 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