3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 5.4.0 - 5.4.30
Parse error: syntax error, unexpected ')', expecting '&' or variable (T_VARIABLE) in /in/k8Diu on line 13
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected ')', expecting '&' or T_VARIABLE in /in/k8Diu on line 13
Process exited with code 255.