php - call grandparent method without calling parent and without modifying parent/grandparent -


i found myself in situation , hacked dirtily. wonder, there clean way?

class base{     var $value;     public function getvalue(){         return 'returned base: '. $value;     } }  class object extends base{     public function getvalue(){         $this->value = 'wrong value';         return parent::getvalue();     } }   class overwrite extends object{     public function getvalue(){         $this->value = 'right value';          ?????      } }  $o = new overwrite; echo $o->getvalue(); 

all i'm allowed edit overwrite. if call parent::getvalue(), value gets overwritten wrong value. if name class, base::getvalue(), base class not have $value property set.

i figured out before finished question, decided post anyway:

base::getvalue() seems correct solution, php seems magic there, base class has $value property set, when called child.


Comments