在下面的示例代码中,父类
Foo
中的test()
方法被子类Bar
中的test()
方法覆盖。是否可以从Bar::test()
中调用Foo::test()
?class Foo
{
$text = "world\n";
protected function test() {
echo $this->text;
}
}// class Foo
class Bar extends Foo
{
public function test() {
echo "Hello, ";
// Cannot use 'parent::test()' because, in this case,
// Foo::test() requires object data from $this
parent::test();
}
}// class Bar extends Foo
$x = new Bar;
$x->test();
foo::test() REQUIRE_DISABLED object data from $this
是什么意思? - nickb