📢 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?
📢 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?
@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?