phpstan icon indicating copy to clipboard operation
phpstan copied to clipboard

Calling ReflectionClass::isSubclassOf() multiple times doesn't narrow types correctly in 8.4

Open dktapps opened this issue 1 month ago • 1 comments

Bug report

The result is correct up to 8.3, but *NEVER* in 8.4 for some reason.

Code snippet that reproduces the problem

https://phpstan.org/r/52a81990-cb4a-4e1b-b638-c5f9b39a5688

Expected output

The same output on all PHP versions

Did PHPStan help you today? Did it make you happy in any way?

No response

dktapps avatar Nov 10 '25 20:11 dktapps

TypeSpecifying is here https://github.com/phpstan/phpstan-src/blob/e870ac104cdf2b6ce67aed0d6e7e1f5cbce9b07f/src/Type/Php/ReflectionClassIsSubclassOfTypeSpecifyingExtension.php#L20

One thing to know is the fact that the ReflectionClass stub change in PHP 8.4 https://github.com/phpstan/phpstan-src/blob/e870ac104cdf2b6ce67aed0d6e7e1f5cbce9b07f/src/PhpDoc/ReflectionClassStubFilesExtension.php#L9

Template type is not covariant anymore https://github.com/phpstan/phpstan-src/blob/e870ac104cdf2b6ce67aed0d6e7e1f5cbce9b07f/stubs/ReflectionClass.stub#L6 vs https://github.com/phpstan/phpstan-src/blob/e870ac104cdf2b6ce67aed0d6e7e1f5cbce9b07f/stubs/ReflectionClassWithLazyObjects.stub#L6

Maybe it imply some fix on TypeSpecifyingExtension side...

VincentLanglet avatar Nov 11 '25 15:11 VincentLanglet