Re: Re: How to build a real Trait thing without exclusion and renaming

From: Date: Wed, 27 Feb 2008 14:33:13 +0000
Subject: Re: Re: How to build a real Trait thing without exclusion and renaming
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-35817@lists.php.net to get a copy of this message
Lukas Kahwe Smith schrieb:
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. I share this objection. Maybe a somewhat handier solution of my proposal would be the option to leave out the method name, but I'm not quite sure whether it is really readable:
class Talker { use A, B, C, D {
     B::smallTalk instead A, C, D; //to be read like: use B::smallTalk
                             // instead the implementations form A, C, D
} }
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() { } } Hm, personally, I would leave this out. The notion is that class definitions will override trait methods in any case (even/especially if traits methods are conflicting). So it would be fine to have this one implicit. This would also avoid construction attempts like: A::bigTalk instead self::bigTalk, A::bigTalk;
Kind Regards Stefan

« previous php.internals (#35817) next »