3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // proof of concept: call method from parents parent class A { private $value = 'please override me'; public function set() { $this->value = 'A was here'; } public function get() { return $this->value; } } class B extends A { public function set() { // do nothing, value is "please override me" } } class C extends B { public function set() { (new ReflectionClass($this))->getParentClass()->getParentClass()->getMethod('set')->getClosure($this)(); } } // as reference, B::set() was overridden: $b = new B; $b->set(); var_dump($b->get()); // "please override me" // and now parent::parent::set() :) $c = new C; $c->set(); var_dump($c->get()); // "A was here"
based on j1Ru8
Output for 7.0.0 - 7.2.0
string(18) "please override me" string(10) "A was here"
Output for 5.4.2 - 5.6.28
Parse error: syntax error, unexpected '(' in /in/0ZuqD on line 32
Process exited with code 255.
Output for 5.3.17 - 5.3.29
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/0ZuqD on line 32
Process exited with code 255.