To me there isn't nothing out-of-order. protected
means visible to this class and all his subclasses.
Let's analyze this snippet
class C3 extends C1
{
public function f()
{
// Calling protected method on parent.
$c1 = new C1();
$c1 -> f();
// Calling protected method on sibling??!?
$c2 = new C2();
$c2 -> f();
echo "c3\n";
}
}
You're overwriting C1->f()
[and this is fine] but first time you're recalling $c1->f()
(as $c1
is an instance of C1
class) and so output is perfectly ok.
Second time you're calling $c2->f()
so no sibling function but C2
class function and this is perfectly legal as you're overwriting this too.
Maybe I don't understand properly your question, but this is the explaination of the above snippet of code