I have a outer class that has another class as a member ( following the principle composition over inheritance ). Now I need to call a method of the outer class from the class within.
class Outer
{
var $inner;
__construct(Inner $inner) {
$this->inner = $inner;
}
function outerMethod();
}
class Inner
{
function innerMethod(){
// here I need to call outerMethod()
}
}
I see as a solution to add a reference in Outer::__construct :
$this->inner->outer = $this;
This allows me to call the outer method like this in Inner::innerMethod :
$this->outer->outerMethod();
Is this a good solution or is there a better alternative ?