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 . ';' : ''; eval(" $namespace class $name extends $class { public function __construct() { \$args = func_get_args(); call_user_func_array('parent::__construct', \$args); } } "); } $reflClass = new \ReflectionClass($extClass); return $reflClass->hewInstanceArgs($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
Fatal error: Uncaught Error: Call to undefined method ReflectionClass::hewInstanceArgs() in /in/s8Hfi:36 Stack trace: #0 /in/s8Hfi(43): instantiatePrivateCtor('Foo', 'bacon') #1 {main} thrown in /in/s8Hfi on line 36
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:
66.95 ms | 401 KiB | 8 Q