Re: [RFC] [Discussion] Bound-Erased Generic Types
| From: | Ben Ramsey | Date: | Mon, 11 May 2026 18:03:49 +0000 |
| Subject: | Re: [RFC] [Discussion] Bound-Erased Generic Types | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-130834@lists.php.net to get a copy of this message | ||
On 5/11/26 03:38, Brent Roose wrote:
Thank you, Seifeddine, for all this work and effort; it was a very clear and even pleasant read. To internals: I'd like to highlight a couple of additional reasons why I think you should vote yes on this final RFC. 1. Although runtime-ignored generics are a paradigm shift compared to PHP's current type system, it's important to note that the target audience for this feature is already very familiar with this workflow. The value of generics (and by extension, the whole type system) for them comes from static type analysis, not the runtime type checker. Why do we need dedicated syntax then, and not stick with docblocks? Because of the reasons outlined in the RFC: a consistent spec and consistent syntax.Many of those on this list who contribute to these discussions are also part of the target audience. Are you trying to make the point that people on internals are not the target audience?
2. Regarding the consistent specification, you may know I work at PhpStorm, so I'd like to highlight how much of a pain the current situation is for us (and also other static analysis vendors). There is no consistency in the details. We have a huge backlog of issues regarding generic type checking that are unsolvable without a proper and consistent spec. PHPStan does X, Psalm does Y, Mago does Z; and most developers expect PhpStorm to support everything. Furthermore, performance is much more a concern for us, as we run our type checker in real time. We would love to improve our generic type support, but a proper spec is required to ensure consistency and a clear path forward. Full disclosure, we tried bringing all static analysis vendors together five or six years ago to create this consistent spec ourselves. These efforts failed, and the only viable option we see is if the spec came from internals.Can you share some of the reasons these efforts failed? If each of these static analysis tools experience problems with conflicting behavior and support, then it seems to me that it behooves all of them to work together to develop a consistent spec. Would PHPStan, Psalm, Mago, etc. be interested in throwing their support behind this RFC (or one like it)?
3. Regarding adding new syntax that doesn't really do anything, there is precedent with attributes. Similar to generics, annotations were a docblock-only feature that got dedicated syntax, without any runtime effect besides reflection. That's exactly the mindset this RFC embraces, and attributes were very well received by the PHP community. I understand some people may fear runtime-ignored generics causing confusion, but I don't think this will be a problem, given that the target audience is: one, used to this workflow already; and, two, attributes already introduced this concept of "syntax that has no runtime effect".There are a handful of predefined attributes that do have runtime (or maybe compile-time?) effects: - AllowDynamicProperties - allows a class to have dynamic properties - Deprecated - causes an E_USER_DEPRECATED error to be emitted - NoDiscard - emits warning if return value not used - Override - fatal error if parent doesn't define method - ReturnTypeWillChange - silences a deprecation notice - SensitiveParameter - redacts values from stack traces
I hope that, along with all the arguments Seifeddine made in the RFC, you seriously consider voting yes on the final RFC, even if you yourself aren't the target audience for this feature. The vast majority of people who would benefit from generics are the people already using static analysis. Speaking with them for years both online and offline, I know most are on board with this approach. (I say "most of them", but truthfully, everyone I spoke with over the years is on board. I just avoid saying "all" because I'm sure someone somewhere disagrees).Have you spoken to folks on this list? I'm part of the target audience, and I've personally been vocal against any proposal for erased types both here and on social media. The one proposal I've been somewhat supportive of is the compile-time generics that Gina and Larry worked on last year[1]. I'm not sure what state it's currently in. Cheers, Ben [1]: https://thephp.foundation/blog/2025/08/05/compile-generics/