📢 We just published a deep dive on compile-time-only generics and we need your feedback!

This isn’t "full generics". It’s a scoped, performance-friendly approach focused on interfaces and abstract classes.

Is this the right direction for PHP?

https://thephp.foundation/blog/2025/08/05/compile-generics/

@thephpf First reaction: yes please!

In particular, I like that this is fully-enforced, and entirely forward-compatible with any future instance-level generics or type inference.

@thephpf A specific thought: if using "Repository<BlogPost>" as a type constraint works, you don't necessarily need a named BlogPostRepository class, because you can use an anonymous class:

$repo = new class extends Repository<BlogPost>;

This looks very close to "$repo = new Repository<BlogPost>{}", but is actually compiled as a class definition. I'm not sure of the performance implications - are anonymous classes preserved in OpCache at all?

@thephpf yes, please! Built-in typed collections would essentially be a replacement for ramsey/collection (and others) which are awesome libraries but we could save ourselves a Composer dependency or two :) Thanks for all the hard work!