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 = dirname($extClass); $name = basename($extClass); eval(" namespace $ns; 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
Warning: Array to string conversion in /in/k8Diu on line 26 Warning: Array to string conversion in /in/k8Diu on line 27 Parse error: syntax error, unexpected token ".", expecting "{" in /in/k8Diu(27) : eval()'d code on line 2
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:
31.2 ms | 401 KiB | 8 Q