Skip to content

Null-safe operator after array access #1916

Description

@uncaught

Motivation:

I sometimes forget that the null-safe operator doesn't work like the coalesce operator. So I would do something like $array[$key]?->someProperty and assume it to work for undefined keys.

Description:

If EA can determine that $array is an array of types other than null, so a null isn't a possible value, then EA should show an error/warning for the syntax above and suggest to change it to ($array[$key] ?? null)?->someProperty instead.

Example

/** @var \SplFileInfo[] $files */
$files = [];
$key = 'foo';
$path = $files[$key]?->getPath();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions