Skip to content

False positive with isset on nullable object's array property key #1884

@ghost

Description

Summary of a problem or a feature request

Checking a nullable object's array property key with isset() yields the following error:

Cannot access property $arrayProperty on Foo|null

Code snippet that reproduces the problem

isset($nullableObject->arrayProperty['key'])

https://phpstan.org/r/7ec5332d-70c0-4307-aa4e-b28b69d712d4

Expected output

No errors.

If $nullableObject is NULL, isset() returns FALSE without any errors.

Changing the condition to isset($nullableObject) && isset($nullableObject->arrayProperty['key']) works, but it's a pointless extra check I'd rather avoid 🙂

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions