Stefan Marr wrote:
<snip>
//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;
}
}
<snip>
Ok, let me give an example code and ask a few questions about it:
trait A {
public function smallTalk() {
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" <[EMAIL PROTECTED]>
<http://www.schmalls.com>
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php