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

From: Date: Tue, 26 Feb 2008 03:19:39 +0000
Subject: Re: How to build a real Trait thing without exclusion and renaming
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-35806@lists.php.net to get a copy of this message
Stefan Marr wrote: <snip> > To get rid of exclude and rename I would like to propose the following: > > //Example from the RFC with the cross-over conflict to be solved > trait A { > public function smallTalk() { > echo 'a'; > } > public function bigTalk() { > echo 'A'; > } > } > > trait B { > public function smallTalk() { > echo 'b'; > } > public function bigTalk() { > echo 'B'; > } > } > > //here the new notion of combing traits and resolving conflicts upfront > class Talker { > use A, B { > B::smallTalk instead A::smallTalk; > A::bigTalk instead B::bigTalk; > A::bigTalk as talk; > } > } This is far better than the original proposal. 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; } } To everyone - this is an aliasing procedure, not a renaming one, and won't affect internal methods of a trait (such as if B::whatever used B::smallTalk), as Richard Quadling incorrectly suggested. Greg

« previous php.internals (#35806) next »