Re: Re: How to build a real Trait thing without exclusion and renaming
| From: | Lukas Kahwe Smith | Date: | Wed, 27 Feb 2008 12:49:58 +0000 |
| Subject: | Re: Re: How to build a real Trait thing without exclusion and renaming | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-35815@lists.php.net to get a copy of this message | ||
On 26.02.2008, at 04:19, Gregory Beaver wrote:
My only objection is that this introduces two new keywords, trait and instead. In addition, this can get very awkward if multiple traits (more than 2) implement the same method name. I would prefer a simple recycling of the "=" sign for both use cases (I'd also accept = for override, "as" for alias). class Talker { use A, B, C, D { smallTalk = A::smallTalk; // this says that if B, C or D implement smallTalk, it is ignored talk = A::bigTalk; } }Well this is not just a different syntax, but an entirely different approach. In Stefan's proposal one had to explicitly handle every conflict manually. in your proposal you do not have to do this. As trait's specifically wanted to get away from automatic conflict resolution when things overlap, I think that Stefan's proposal makes more sense. BTW Stefan: Whats the syntax for when you want to override a trait method with one inside the class definition? I guess one would use "self::" like so: class Talker { use A, B {
B::smallTalk instead A::smallTalk;
self::bigTalk instead B::bigTalk, A::bigTalk;
A::bigTalk as talk;
}
function smallTalk() {
}
}
I also assume that we would mandate signature compatibility (which IMHO should only throw an E_STRICT and not a fatal like what we currently do for inheritance in PHP6)?
regards,
Lukas