I disagree with the argument “you cannot do this” - you can do this with Reflection .
Consider the following class structure:
class A { function foo() { echo 'A'; } } class B extends A { function foo() { parent::foo(); echo 'B'; } } class C extends B { function foo() { parent::foo(); echo 'C'; } }
When initializing with this:
$o = new C; $o->foo();
Will be printed (as expected in this demo ):
ABC
The challenge is to remove B from the output, effectively only executing A foo() and C foo() . So, go to Reflection and take the A foo() method and call it on the C object. Now consider this alternative definition for C :
class C extends B { function foo() { $ref = new ReflectionClass( $this); $parent = $ref->getParentClass()->getParentClass(); $parent->getMethod( 'foo')->invoke( $this); echo 'C'; } }
Now you will only get the output (as shown in this demo ):
AC
Regardless of whether this is “good practice”, it depends on the OP. I think I demonstrated that you can skip the implementation of function B and call the grandparent function from the grandson class.
nickb source share