我有以下代码,我希望返回“WORKED”,但什么也不返回。
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();
路由器:
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();
因为我$bar
从Foo
类定义,并且,扩展AnotherBar
至Foo
,我希望得到已经定义的变量Foo
。
我看不出有什么问题。我从哪里开始?
谢谢!