Bug report
Optional keys on objects can be coalesced, but in PHPStan they result in the error type.
This works:
class Test {}
$a = new \stdClass();
$b = new Test();
var_dump($a->optional ?? null, $b->optional ?? null);
Accessing $b->optional without coalesce results in Warning: Undefined property.
Code snippet that reproduces the problem
https://phpstan.org/r/1f24e6ab-289c-45ad-861c-1f7455f55723
Expected output
Both types should be int|null
Did PHPStan help you today? Did it make you happy in any way?
It does! I get excited every time a new PhpStan version is released!