Re: [Initial Feedback] Typed Arrays

From: Date: Thu, 27 Jun 2024 20:15:56 +0000
Subject: Re: [Initial Feedback] Typed Arrays
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-123960@lists.php.net to get a copy of this message
> 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

« previous php.internals (#123960) next »