Re: How to build a real Trait thing without exclusion and renaming
| From: | Joshua Thompson | Date: | Wed, 27 Feb 2008 01:39:21 +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-35811@lists.php.net to get a copy of this message | ||
Stefan Marr wrote:
<snip>
//Example from the RFC with the cross-over conflict to be solved trait A { public function smallTalk() {Ok, let me give an example code and ask a few questions about it: 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;} } <snip>
return 'a';} public function bigTalk() {
return strtoupper( $this->smallTalk() );} } trait B { public function smallTalk() {
return 'b';} public function bigTalk() {
return strtoupper( $this->smallTalk() );} } class Talker { use A, B {
B::smallTalk instead A::smallTalk;
A::bigTalk instead B::bigTalk;
A::bigTalk as talk;
}
}
// now to the questions
$talker = new Talker();
echo $talker->talk(); // What does this echo? My assumption is 'B'.
echo $talker->bigTalk(); // How about this?
echo $talker->smallTalk(); // This should be 'b'.
All the discussion seems to be on not breaking a traits methods and to call internal methods from the trait. If this is the case, then the answer to the second question would be 'A', which would not break the trait's internal method call, but it seems less obvious to me.
--
"Joshua Thompson" <spam.goes.in.here@gmail.com>
<http://www.schmalls.com>