A PHP internals mailing list discussion about a proposed RFC for bound-erased generic types in PHP. The RFC proposes adding generic type parameters to classes, interfaces, traits, functions, methods, closures, and arrow functions, with bounds, defaults, and variance markers. Type parameters erase to their bound at runtime, while the pre-erasure form is preserved for Reflection and static analyzers. The discussion covers key design decisions including: ordering restrictions for mutually-recursive type parameters, intersection type restrictions with unbounded generics, arity validation being opt-in via turbofish syntax, diamond inheritance checks, the use of turbofish (::< >) syntax for explicit type arguments, and +/- markers for covariance/contravariance. The RFC author responds to each concern, clarifying that arity validation only fires when turbofish is explicitly used, making the feature backward-compatible. The design is intentionally bound-erased for now but structured to support reified generics in a future RFC.

4h 39m read timeFrom externals.io
Post cover image
179 Impressions