I am starting to get into OOP with PHP 5. Can someone please tell me why this doesn't work:
<?php
class Base {
public $test = NULL;
public function __construct() {
$this->load();
}
public function load() {
$this->test = new Test();
}
}
class Test {
public $var1 = 'test1';
public $var2 = NULL;
public function __construct() {
$this->var2 = 'test2';
}
}
$base = new Base();
class Content extends Base {
public function __construct() {
$this->main();
}
public function main() {
echo 'test<br>';
echo $this->test->var1;
echo '<br>';
echo $this->test->var2;
}
}
$content = new Content();
?>
It only outputs the first echo of "test". What I want to do is create a base class that starts all the other classes and then have a class that extends base that can call everything in base and the other classes.
In my example Base starts Test which sets some variables. Then I create Content which extends base. I want to be able to call var1 and var2 in the Test class.
I might be all messed up. Any help would be greatly appreciated.
Thanks,
Alex