I have two PHP traits that each inherit from the same 3rd trait:
trait C {
public function smallTalk() {
echo 'c';
}
}
trait A {
use C;
public function ac() {
echo 'a'.smallTalk();
}
}
trait B {
use C;
public function bc() {
echo 'b'.smallTalk();
}
}
And I want to use them both in a class:
class D {
use A, B;
public function acbc() {
echo ac().bc();
}
}
but I keep getting the error
Fatal error: Trait method smallTalk has not been applied, because there are collisions with other trait methods on D
I know use_once
is not a thing, but I am looking for the same functionality that require_once
or include_once
provides, but for traits. This example is simplified. My real C
has lots of methods and is inherited by many more than 2 traits, so I don't really want to have to repeat a long string of insteadof
every time I use more than 1 of these traits.