I've been searching around the net for answers but couldn't find anything relevant, so I thought about asking it here.
How can I reach functions from a extended class through it's parent class?
Base (parent class)
require_once('FirstChild.class.php');
require_once('SecondChild.class.php');
class Base {
public $first;
public $second;
function __construct() {
$this->first = new FirstChild();
$this->second = new SecondChild();
}
}
First (child class)
class FirstChild extends Base {
public $firstVar;
function __construct() {
$this->firstVar = 'Hello';
}
public function getSecondVar() {
echo parent::$second->getVar();//doesnt work!!?
}
}
Second (child class)
class SecondChild extends Base {
public $secondVar;
function __construct() {
$this->secondVar = 'World';
}
public function getVar() {
return $this->secondVar;
}
}
How can the "getSecondVar" function be reached inside "FirstChild"?
Thanks!