On 10 May 2026 20:02:32 BST, 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.

Hi Seifeddine,

Thanks for putting together this proposal.

However, I am generally against any *unenforced* implementation of generics. I 
choose that word carefully: it is not type erasure per se that I am against, 
but the ability to write code which *looks like* it enforces particular 
signatures, but actually does not.

There is lots of background in the RFC, but one relevant comparison not 
referenced is Python, where all type hints are unenforced. Static analysis has 
to be run manually, so code can be written, and even published as a library, 
with completely incorrect type information. Users of that code then make 
reasonable assumptions based on the published types, and get unexpected 
run-time behaviour.

Note that this is fundamentally different from the experience of languages like 
Java or TypeScript, where type information may be erased, but is still 
*enforced*, because static analysis is a compulsory part of the compilation 
process.

Having most types enforced is obviously better than none, but as far as I can 
see the same risk exists - someone can write code that claims to use generics, 
and publish it to Packagist without actually checking it; or write supposed 
invariants which only hold if the user also analyses their own code. This is 
true today, of course, but the claims are much weaker, sitting in docblocks not 
native syntax.

Once we go down this route, it will be very hard to change our minds, because 
enforcing types in code which previously ignored them would be a breaking 
change.

I think the only options I would personally support are:

a) run-time enforced generics in limited positions (as in the blog post you 
link to from Gina and Larry)

b) generics which are erased at compile-time *by a tool that also enforces 
them* (as in Java, TypeScript, etc)

Regards,

Rowan Tommins
[IMSoP]

Reply via email to