「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
。
何が悪いのかわかりません。どこから始めますか?
ありがとう!