I have a main class and two extended classes:
class Main {
public $foo;
}
class A extends Main {
public function setVar()
{
$foo = "test";
}
}
class B extends Main {
public function getVar()
{
return $this->foo;
}
}
$A = new A;
$B = new B;
$A->setVar();
echo "result: ".$B->getVar();
But result ($B->getVar()) stays empty. I am clearly missing something simple here… Besides that, is this the way to go splitting long classes up in relevant subclasses?
Example of using Dependency Injection (DI) to share an instance of Main between to different class instances rather than trying to use inheritence