在下面的示例代码中,父类 Foo
中的方法 test()
被子类中的方法 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();
最佳答案
关于php - 调用重写的父方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8073471/