سلام و عرض ادب
در داکیومنت 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
اگر ممکن هست علت چاپ سه بار عبارت success! رو توضیح بدید ممنون میشم.
همینطور هم در مورد اروری که بر خورده.