Let’s say I have three classes. One being the parent and two being “childs”. However, I’m not using class - extends -:
class root
{
function root(){
$this->son = new son();
$this->daughter = new daughter();
}
}
class son
{
...
}
class daughter
{
...
}
How could I call a function of son from a function of daughter? In other words, how could I reference the class root from son/daughter so that I could call functions of each other, from each other?
A classic case of dependency injection.
Just be careful not to create rigid dependencies between classes that shouldn’t have them. Inheritance may be the better way to go. Alternatives include the registry pattern and factory patterns.