kil*_*129 26 php overriding object
在以下示例代码,该方法test()在父类Foo是由该方法覆盖test()在子类Bar.是否有可能调用Foo::test()从Bar::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();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23449 次 |
| 最近记录: |