> Is there a reason why traits can't be used to introduce generics? > i.e. extending the code that composes the trait into the class to > replace the generic type? eg. in `zend_add_trait_method`? > (I couldn't quickly find where trait properties get added, even > though my example is for properties.) > > trait GenericTrait<T> > { > private ?T $object = null; > } > > class ComposableClass > { > use GenericTrait<Foo>; > } > > // Result: > class ComposedClass > { > private ?Foo $object = null; > } > > Just a random thought... > > Regards, > radar3301
I worked with Joe Watkins to do a proof-of-concept for generic traits. It's a bit old since it's from 2017, but could be a useful starting point if you are serious about pursuing this idea: https://github.com/php/php-src/compare/master...morrisonlevi:php-src:parameterized_traits