3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function super(... $args) { $trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS, 2); if(($object = $trace[1]["object"]) || ($object = $trace[1]["class"])) { $method = $trace[1]["function"]; $parent = get_parent_class($object); if(method_exists($parent, $method)) { $method = new ReflectionMethod($parent, $method); return $method->invoke(is_object($object) ? $object : NULL); } else throw new BadMethodCallException("Method " . $parent . "::" . $method ." does not exist."); } else throw new BadFunctionCallException("super() can only be called from a class context."); } class HasSuper { protected function super(... $args) { $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); $method = $trace[1]["function"]; $parent = get_parent_class($this); if(method_exists($parent, $method)) { $method = new ReflectionMethod($parent, $method); $method->invoke($this); } else throw new BadMethodCallException("Method " . $callback . " does not exist."); } } class Foo extends HasSuper { public function hello() { echo("Hello World!" . PHP_EOL); } } class Bar extends Foo { public function hello() { $this->super(); super(); } } $bar = new Bar; $bar->hello();
based on 2j5XQ
Output for 5.6.0 - 5.6.30, hhvm-3.15.4 - 3.17.3, 7.0.0 - 7.3.0alpha1
Hello World! Hello World!
Output for hhvm-3.12.14
Assertion failure: /tmp/tmp.V3wJAhcnRu/hphp/runtime/base/runtime-error.cpp:48: void HPHP::raise_error(const string&): assertion `0' failed.
Process exited with code 134.