我在阅读有关LSB功能PHP手册中,我理解它是如何工作在静态情况下,但我不很明白它在非静态上下文。 手册中的示例是这样的:
<?php
class A {
private function foo() {
echo "success!\n";
}
public function test() {
$this->foo();
static::foo();
}
}
class B extends A {
/* foo() will be copied to B, hence its scope will still be A and
* the call be successful */
}
class C extends A {
private function foo() {
/* original method is replaced; the scope of the new one is C */
}
}
$b = new B();
$b->test();
$c = new C();
$c->test(); //fails
?>
输出是这样的:
success!
success!
success!
Fatal error: Call to private method C::foo() from context 'A' in /tmp/test.php on line 9
我不明白B类,如何在A的私有方法可以被继承到B? 任何人都可以引导我这到底是怎么回事呢? 非常感谢!