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
{{ message }}
Repository navigation
PHPStan incorrectly narrows type of object after an instanceof check #13713
When an instanceof check is used on a variable typed as object, PHPStan incorrectly infers its type as the concrete class (T) instead of the correct intersection type (object&T). This leads to a false-positive with a subsequent is_subclass_of() check since PHPStan believes that the same type is being supplied to its first and second parameters.
Consult the linked test snippet for more detail about the erroneous pattern.
stdClass doesn't means exactly a stdClass, it means stdClass and all the child classes.
So it's correct to simplify stdClass&object to stdClass in your example.
Activity
VincentLanglet commentedon Oct 23, 2025
stdClassdoesn't means exactly a stdClass, it means stdClass and all the child classes.So it's correct to simplify
stdClass&objecttostdClassin your example.What is not correct is the result of
is_subclass_of, which is shown byhttps://phpstan.org/r/0cf1fbc5-1934-4dd8-b30c-dcba30a8cb48
The issue seems related to https://github.com/phpstan/phpstan-src/blob/dd2717b2046823a18d431b462acc0cdee2fe5ddb/src/Type/Php/IsAFunctionTypeSpecifyingHelper.php#L46-L48
There is currently no differences between
and
VincentLanglet commentedon Oct 23, 2025
I'll try fixing it with phpstan/phpstan-src#4472 (WIP)
phpstan-bot commentedon Feb 26, 2026
Closed via merging phpstan/phpstan-src#4472
github-actions commentedon Mar 30, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.