3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Hoge { private $_name; private $_var; private $_default = "class default"; private function __construct($name) { $this->_name = $name; $this->_var = "set by constructor"; printf("Side effect %s\n", get_class($this)); } } function newInstanceWithoutConstructor($class) { $extended = sha1($class) . $class; if(!class_exists($extended)) { $classCode = "class $extended extends $class { public function __construct(){} }"; eval($classCode); } $dried = serialize(new $extended); $fresh = unserialize(str_replace( strlen($extended) . ':"' . $extended . '"', strlen($class) . ':"' . $class . '"', $dried )); return $fresh; } $a = newInstanceWithoutConstructor("Hoge"); assert(is_a($a, "Hoge")); var_dump($a);

preferences:
34.13 ms | 402 KiB | 5 Q