3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $foo; private function __construct($spam){ $this->foo = $spam; } public function getFoo() { return $this->foo; } } function instantiatePrivateCtor($class /*, $...args */) { $args = array_slice(func_get_args(), 1); $extClass = $class . '__Ext'; if (!class_exists($extClass)) { $ns = ltrim(dirname($extClass), '\\'); $name = basename($extClass); $namespace = $ns && $ns !== '.' ? 'namespace ' . $ns . ';' : ''; echo(" $namespace class $name extends $class { public function __construct() { \$args = func_get_args(); call_user_func_array('$class::__construct', \$args); } } "); } $reflClass = new \ReflectionClass($extClass); return $reflClass->newInstanceArgs($args); } $args = 'bacon'; $class = 'Foo'; $reflClass = new \ReflectionClass($class); $instance = instantiatePrivateCtor($class, 'bacon'); echo $instance->getFoo();
Output for git.master, git.master_jit, rfc.property-hooks
class Foo__Ext extends Foo { public function __construct() { $args = func_get_args(); call_user_func_array('Foo::__construct', $args); } } Fatal error: Uncaught ReflectionException: Class "Foo__Ext" does not exist in /in/Usuc7:35 Stack trace: #0 /in/Usuc7(35): ReflectionClass->__construct('Foo__Ext') #1 /in/Usuc7(43): instantiatePrivateCtor('Foo', 'bacon') #2 {main} thrown in /in/Usuc7 on line 35
Process exited with code 255.

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:
45.55 ms | 402 KiB | 8 Q