How can I deal with traits with methods of same name?
trait FooTrait {
public function fooMethod() {
return 'foo method';
}
public function getRow() {
return 'foo row';
}
}
trait TooTrait {
public function tooMethod() {
return 'too method';
}
public function getRow() {
return 'too row';
}
}
class Boo
{
use FooTrait;
use TooTrait;
public function booMethod() {
return $this->fooMethod();
}
}
error,
Fatal error: Trait method getRow has not been applied, because there
are collisions with other trait methods on Boo in...
What should I do about it?
And also, with two same method names, how can I get the method from trait FooTrait
?
$a = new Boo;
var_dump($a->getRow()); // Fatal error: Call to undefined method Boo::getRow() in...
Edit:
class Boo
{
use FooTrait, TooTrait {
FooTrait::getRow insteadof TooTrait;
}
public function booMethod() {
return $this->fooMethod();
}
}
what if I want to get the method getRow
from TooTrait
via Boo
as well? Is it possible?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…