PHP still missing bits: generics.
Keven Godet

Generics are a programming concept that some languages have and PHP doesn’t, but I don’t think your example is particularly compelling.

Why not just remove the type hint on the return? If this is a class you’ve written for generating mocks for testing, are you really worried that someone else is going to extend DistributedGenerator and change the return types?

And far and away, the most common examples of collections in PHP are model based. Whether we’re using activerecord or repositories, usually the collection objects are shared across lots of models. To get into a situation where you’d be able to benefit from generics with a model collection, you’d have to be in a situation where you’d expect users of your library to extend and replace a collections for specific models, wouldn’t you?

Generics seemed handy in Java as a way to let a strictly typed language not be strictly typed. For PHP, we have dynamic types already, so generics don’t seem to add much to me.