0
我有以下代码,我希望返回“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
已定义的变量。
我看不出有什么问题。我开始在哪里凸轮?
谢谢!
是的,我知道这个错误。将更新我的问题。 –
问题已更新。 –