So I've been working on upgrading my open-source libraries to be fully compatible with PHP 8.5: ๐ค Technically Callable Reflection, specifically, and stumbled upon this change in the Reflections API that was not mentioned in the release notes.
Starting PHP 8.5 the ReflectionNamedType values created for self and parent type hints
no longer contain the actual self and parent types. Instead, they are unwrapped
during compile-time to the corresponding class names, as if they were in the code.
class MyClass { public function equals(self $another): bool { // ... } } $reflection = new ClassReflection(MyClass::class); var_dump( $reflection->getMethod('equals') ->getParameters()[0] ->getType() ->getName(), );
The above snippet outputs self in PHP versions prior to 8.5:
string(4) "self"
and MyClass in PHP 8.5 and later:
string(7) "MyClass"
Same story with parent type hints.
Proof: https://github.com/php/php-src/issues/21284
If you're relying on the Reflections API in your code (like, if you maintain a Service Container implementation supporting auto-wiring) โ double-check if this has not introduced a bug into your logic.
Let me know what you think about it.
๐ Cheers!