PHP: call method in the context of each object of the inheritance chain
<p>Look at the following code snippet:</p>

<pre><code>&lt;?php

class A {
        function fn() {
                print 'Context: Class:' . get_class($this) 
                        . ' Parent:' . get_parent_class($this) . "\n";
                if(get_parent_class($this)) {
                        parent::fn();
                }
        }
}

class B extends A { }
class C extends B { }

$a = new A();
$c = new C();

$a-&gt;fn();

print "\n";

$c-&gt;fn();

?&gt;
</code></pre>

<p>By running it you will get the following output:</p>

<pre><code>Context: Class:A Parent:

Context: Class:C Parent:B

Fatal error: Cannot access parent:: when current class scope has no parent in /home/andrei/test/test.php on line 10
</code></pre>

<p>I believe it should be something like this:</p>

<pre><code>Context: Class:A Parent:

Context: Class:C Parent:B
Context: Class:B Parent:A
Context: Class:A Parent:
</code></pre>

<p>What do you think? If <code>get_parent_class($this)</code> returns a not false value should we safely assume parent:: is defined? In what class context is <code>fn()</code> called?</p>
