Skip to content

Cannot use null coalescing operator $arr[0][1] ?? '' when array entries are optional #4432

@simPod

Description

@simPod

Bug report

When using array shape with optional entries array{client?: array{id: string}} one cannot use null coalescing operator to handle undefined entry as $arr['client']['id'] ?? '' which is valid code https://3v4l.org/kLE5G

PHPStan says

Offset 'client' does not exist on array(?'client' => array('id' => string)).

Code snippet that reproduces the problem

https://phpstan.org/r/3d07aaf8-0cd3-467e-9173-c3ba9dd3369b

Expected output

No errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions