<?php
class A {
private function foo() {
echo "[A#foo] success!\n";
}
public function test() {
echo "[A#test] calling instance method\n";
$this->foo();
echo "[A#test] calling via static\n";
static::foo();
}
}
class B extends A {
/* foo() будет скопирован в В, следовательно его область действия по прежнему А,
и вызов будет успешен*/
}
class C extends A {
private function foo() {
/* исходный метод заменен; область действия нового метода С */
echo "[C#foo]\n";
}
}
$b = new B();
$b->test();
$c = new C();
$c->test(); //не верно
PD9waHAKY2xhc3MgQSB7CiAgICBwcml2YXRlIGZ1bmN0aW9uIGZvbygpIHsKICAgICAgICBlY2hvICJbQSNmb29dIHN1Y2Nlc3MhXG4iOwogICAgfQogICAgcHVibGljIGZ1bmN0aW9uIHRlc3QoKSB7CiAgICAgICAgZWNobyAiW0EjdGVzdF0gY2FsbGluZyBpbnN0YW5jZSBtZXRob2RcbiI7CiAgICAgICAgJHRoaXMtPmZvbygpOwogICAgICAgIGVjaG8gIltBI3Rlc3RdIGNhbGxpbmcgdmlhIHN0YXRpY1xuIjsKICAgICAgICBzdGF0aWM6OmZvbygpOwogICAgfQp9CgpjbGFzcyBCIGV4dGVuZHMgQSB7CiAgIC8qIGZvbygpINCx0YPQtNC10YIg0YHQutC+0L/QuNGA0L7QstCw0L0g0LIg0JIsINGB0LvQtdC00L7QstCw0YLQtdC70YzQvdC+INC10LPQviDQvtCx0LvQsNGB0YLRjCDQtNC10LnRgdGC0LLQuNGPINC/0L4g0L/RgNC10LbQvdC10LzRgyDQkCwKICAgICAg0Lgg0LLRi9C30L7QsiDQsdGD0LTQtdGCINGD0YHQv9C10YjQtdC9Ki8KfQoKY2xhc3MgQyBleHRlbmRzIEEgewogICAgcHJpdmF0ZSBmdW5jdGlvbiBmb28oKSB7CiAgICAgICAgLyog0LjRgdGF0L7QtNC90YvQuSDQvNC10YLQvtC0INC30LDQvNC10L3QtdC9OyDQvtCx0LvQsNGB0YLRjCDQtNC10LnRgdGC0LLQuNGPINC90L7QstC+0LPQviDQvNC10YLQvtC00LAg0KEgKi8KICAgICAgICBlY2hvICJbQyNmb29dXG4iOwogICAgfQp9CgokYiA9IG5ldyBCKCk7CiRiLT50ZXN0KCk7CiRjID0gbmV3IEMoKTsKJGMtPnRlc3QoKTsgICAvL9C90LUg0LLQtdGA0L3Qvgo=