3v4l.org

run code in 300+ PHP versions simultaneously
<?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();
Output for git.master, git.master_jit, rfc.property-hooks
Hello World! Hello World!

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
58.65 ms | 401 KiB | 8 Q