Gracias a ‘supu’ por la explicación detallada
“La herencia múltiple tiene un problema de ambigüedad a referenciar a métodos o atributos que se llaman igual en diferentes padres.
Es lo que se hacía antes con una interfaces y patrón representante.
A ver cuando hacen herencia múltiple de verdad…”
supu; }
public function whoYouAre() { return $this->supu; }
}
class B implements I {
private $supu = "B";
public function whoIam() { return $this->supu; }
public function whoYouAre() { return $this->supu; }
}
class C extends A implements I {
private $b_instance = new B();
public function whoYouAre() {
return $this->b_instance->whoYouAre();
}
}
// herencia multiple con el parche de los trait
trait A {
public function whoIam() { return "A"; }
public function whoYouAre() { return "A"; }
}
trait B {
public function whoIam() { return "B"; }
public function whoYouAre() { return "B"; }
}
class C {
use A, B {
A::whoIAm insteadof B;
B::whoYouAre insteadof A;
}
}
?>