<?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: Uncaught Error: Call to private method C::foo() from scope A in /in/8Dt1r:9
Stack trace:
#0 /in/8Dt1r(27): A->test()
#1 {main}
thrown in /in/8Dt1r on line 9
Process exited with code 255.
success!
success!
success!
Fatal error: Uncaught Error: Call to private method C::foo() from context 'A' in /in/8Dt1r:9
Stack trace:
#0 /in/8Dt1r(27): A->test()
#1 {main}
thrown in /in/8Dt1r on line 9
Process exited with code 255.