-
-
Notifications
You must be signed in to change notification settings - Fork 946
Closed
Description
Bug report
In php8, the new null safe operator ?-> was added. When using it in combination with ?? for calling method/accesing properties on values of array like this:
($array['key'] ?? null)?->barphpstan incorrectly reports
Cannot access property $bar on T|null.
even though we are using the null safe operator, and the code behaves as expected (return nulls, when the key in the array does not exist).
Code snippet that reproduces the problem
https://phpstan.org/r/d831442b-e70b-48eb-b8ac-d68332590815
<?php declare(strict_types = 1);
class Foo
{
public function foo(): void
{
/** @var Bar[] */
$array = [];
$value = ($array['randomKey'] ?? null)?->bar;
}
}
class Bar {
public mixed $bar;
}Expected output
To not report any errors
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels