Skip to content

Null coalesce operator on nested array returns unexpected error #8069

@alexander-schranz

Description

@alexander-schranz

Bug report

The ?? usage on a nested array which parent key does not exist throwns an error but I would not expect it e.g.:

/** @var mixed[] $test */
$test = [];

var_dump($test['hello'][0] ?? 'world');

Code snippet that reproduces the problem

https://phpstan.org/r/42618f11-503b-4ad6-ae43-0a2d642deff8

https://3v4l.org/hdYaB

Its a similar issue to isset but instead the ?? (Null coalesce operator) is used: #8068

Expected output

No error should be shown

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

We are shipping phpstan as part of our Sulu CMS skeleton since last 2.5 minor version to improve with rector the upgrade process and code quality of all Sulu based projects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions