You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When checking a method call result of type ?object in an IF or ternary operator and the using it (i.e. $a->getB() ? $a->getB()->getC()) the null type is probably not removed from the type combinator (see example below).
I would understand that behavior if there were some reasons that would make it hard to detect (like method can return something else on second call, etc.) but that seems not to be the case since $a->getB() !== null ? $a->getB()->getC() works.
Summary of a problem or a feature request
When checking a method call result of type
?object
in an IF or ternary operator and the using it (i.e.$a->getB() ? $a->getB()->getC()
) thenull
type is probably not removed from the type combinator (see example below).I would understand that behavior if there were some reasons that would make it hard to detect (like method can return something else on second call, etc.) but that seems not to be the case since
$a->getB() !== null ? $a->getB()->getC()
works.Code snippet that reproduces the problem
Error: https://phpstan.org/r/bcbe85f9b434c0e1a4376925e89f06c3
This works: https://phpstan.org/r/e4e5a4574f1e61472681bb3d1b981b3a
Expected output
No errors.
This can of course easily be fixed by writing better code but for setting up PHPStan for legacy codebases it is not very useful.
The text was updated successfully, but these errors were encountered: