Re: [Initial Feedback] Typed Arrays

From: Date: Wed, 26 Jun 2024 23:08:12 +0000
Subject: Re: [Initial Feedback] Typed Arrays
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Several people said:
> generics

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


Thread (39 messages)

« previous php.internals (#123902) next »