On Tue, 12 May 2026 at 10:07, Seifeddine Gmati <[email protected]> wrote:
> Hello Internals, > > I'd like to start the discussion on a new RFC adding bound-erased > generics types to PHP. > > Generic type parameters can be declared on classes, interfaces, > traits, functions, methods, closures, and arrow functions, with > bounds, defaults, and variance markers. Type parameters erase to their > bound at runtime; the pre-erasure form is preserved for Reflection and > consumed by static analyzers. > > - RFC: https://wiki.php.net/rfc/bound_erased_generic_types > - Implementation: https://github.com/php/php-src/pull/21969 > > Thanks, > Seifeddine. > This is just from the perspective of a static analysis tool author, but I hope it's instructive: Currently every return, param type and property type requires two fields: the type in the signature and the type in the docblock. These can sometimes be different types, and each static analysis tool has its own way of dealing with the discrepancy. Furthermore, people will sometimes omit the docblock type definition on child class definitions of those methods, and static analysis tools need their own way to handle those discrepancies too. When I ported Psalm to run on Hack code (whose type structure mirrors this RFC) I was able to remove all of that code, which made the implementation much more straightforward and memory-efficient. I understand that improving the static analysis data model should not, on its own, be a reason to merge, but I just wanted to relate how much easier this model makes things. Best wishes, Matt
