I have the follow code, which I expect to return “WORKED”, But returning nothing.
class Foo {
public function __construct() {
echo('Foo::__construct()<br />');
}
public function start() {
echo('Foo::start()<br />');
$this->bar = new Bar();
$this->anotherBar = new AnotherBar();
}
}
class Bar extends Foo {
public function test() {
echo('Bar::test()<br />');
return 'WORKED';
}
}
class AnotherBar extends Foo {
public function __construct() {
echo('AnotherBar::__construct()<br />');
echo($this->bar->test());
}
}
$foo = new Foo();
$foo->start();
Router:
Foo::__construct() <- From $foo = new Foo();
Foo::start() <- From Foo::__construct();
Foo::__construct() <- From $this->bar = new Bar();
AnotherBar::__construct() <- From $this->anotherBar = new AnotherBar();
Because I define $bar from Foo class, and, extend AnotherBar to Foo, I expect to get variables already defined from Foo.
I can’t see what is wrong. Where cam I start?
Thanks!
The
AnotherBarinstance never had itsstartmethod called so its$this->baris undefined.With errors being displayed you get the following messages:
You can include the following code right after you
<?phpline to see all errors:Of course you can also do this via
php.iniwhich would be a cleaner solution.