在不调用parent和不修改parent/grandparent的情况下调用grandparent方法


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

我发现自己在这种情况下,我只是黑它肮脏。但我想知道,有没有什么干净的方法?

class base{
    var $value;
    public function getValue(){
        return 'returned from 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();

我只能编辑overwrite。如果我调用parent::getValue(),这个值会被错误的值覆盖。如果我将类命名为base::getValue(),则基类不会设置$value属性。

我在回答完这个问题之前就明白了,但我还是决定把它贴出来:

base::getValue()似乎是正确的解决方案,php似乎在那里做了一些魔法,所以base类有$value属性设置,当从它的子调用