3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $classNames = array("StdClass", "ArrayObject", "SplFileObject"); foreach($classNames as $className) { var_dump(instanitateWithoutConstructorThroughUnserialize($className)); var_dump(instanitateWithoutConstructorThroughReflection($className)); } function instanitateWithoutConstructorThroughUnserialize($className) { return unserialize(sprintf('O:%d:"%s":0:{}', strlen($className), $className)); } function instanitateWithoutConstructorThroughReflection($className) { try { $ref = new ReflectionClass($className); return $ref->newInstanceWithoutConstructor(); } catch (ReflectionException $e) { return $e; } }
Output for 5.6.8 - 5.6.28, 7.0.0 - 7.1.0
object(stdClass)#1 (0) { } object(stdClass)#2 (0) { } Warning: Erroneous data format for unserializing 'ArrayObject' in /in/7DM7S on line 10 Notice: unserialize(): Error at offset 22 of 23 bytes in /in/7DM7S on line 10 bool(false) object(ArrayObject)#1 (1) { ["storage":"ArrayObject":private]=> array(0) { } } Warning: Erroneous data format for unserializing 'SplFileObject' in /in/7DM7S on line 10 Notice: unserialize(): Error at offset 24 of 25 bytes in /in/7DM7S on line 10 bool(false) object(SplFileObject)#2 (1) { ["pathName":"SplFileInfo":private]=> string(0) "" }
Output for hhvm-3.10.0 - 3.12.0
object(stdClass)#1 (0) { } object(stdClass)#2 (0) { } object(ArrayObject)#2 (1) { ["storage":"ArrayObject":private]=> array(0) { } } object(ArrayObject)#3 (1) { ["storage":"ArrayObject":private]=> array(0) { } } object(SplFileObject)#3 (12) { ["delimiter":"SplFileObject":private]=> string(1) "," ["enclosure":"SplFileObject":private]=> string(1) """ ["escape":"SplFileObject":private]=> string(1) "\" ["flags":"SplFileObject":private]=> NULL ["filename":"SplFileObject":private]=> NULL ["maxLineLen":"SplFileObject":private]=> int(0) ["currentLineNum":"SplFileObject":private]=> int(0) ["rsrc":"SplFileObject":private]=> NULL ["currentLine":"SplFileObject":private]=> bool(false) ["fileName":"SplFileInfo":private]=> NULL ["fileClass":"SplFileInfo":private]=> string(13) "SplFileObject" ["infoClass":"SplFileInfo":private]=> string(11) "SplFileInfo" } object(SplFileObject)#4 (12) { ["delimiter":"SplFileObject":private]=> string(1) "," ["enclosure":"SplFileObject":private]=> string(1) """ ["escape":"SplFileObject":private]=> string(1) "\" ["flags":"SplFileObject":private]=> NULL ["filename":"SplFileObject":private]=> NULL ["maxLineLen":"SplFileObject":private]=> int(0) ["currentLineNum":"SplFileObject":private]=> int(0) ["rsrc":"SplFileObject":private]=> NULL ["currentLine":"SplFileObject":private]=> bool(false) ["fileName":"SplFileInfo":private]=> NULL ["fileClass":"SplFileInfo":private]=> string(13) "SplFileObject" ["infoClass":"SplFileInfo":private]=> string(11) "SplFileInfo" }
Output for 5.4.30 - 5.5.35
object(stdClass)#1 (0) { } object(stdClass)#2 (0) { } object(ArrayObject)#2 (1) { ["storage":"ArrayObject":private]=> array(0) { } } object(ReflectionException)#1 (7) { ["message":protected]=> string(99) "Class ArrayObject is an internal class that cannot be instantiated without invoking its constructor" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/7DM7S" ["line":protected]=> int(16) ["trace":"Exception":private]=> array(2) { [0]=> array(6) { ["file"]=> string(9) "/in/7DM7S" ["line"]=> int(16) ["function"]=> string(29) "newInstanceWithoutConstructor" ["class"]=> string(15) "ReflectionClass" ["type"]=> string(2) "->" ["args"]=> array(0) { } } [1]=> array(4) { ["file"]=> string(9) "/in/7DM7S" ["line"]=> int(6) ["function"]=> string(46) "instanitateWithoutConstructorThroughReflection" ["args"]=> array(1) { [0]=> string(11) "ArrayObject" } } } ["previous":"Exception":private]=> NULL } Warning: Erroneous data format for unserializing 'SplFileObject' in /in/7DM7S on line 10 Notice: unserialize(): Error at offset 24 of 25 bytes in /in/7DM7S on line 10 bool(false) object(ReflectionException)#2 (7) { ["message":protected]=> string(101) "Class SplFileObject is an internal class that cannot be instantiated without invoking its constructor" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/7DM7S" ["line":protected]=> int(16) ["trace":"Exception":private]=> array(2) { [0]=> array(6) { ["file"]=> string(9) "/in/7DM7S" ["line"]=> int(16) ["function"]=> string(29) "newInstanceWithoutConstructor" ["class"]=> string(15) "ReflectionClass" ["type"]=> string(2) "->" ["args"]=> array(0) { } } [1]=> array(4) { ["file"]=> string(9) "/in/7DM7S" ["line"]=> int(6) ["function"]=> string(46) "instanitateWithoutConstructorThroughReflection" ["args"]=> array(1) { [0]=> string(13) "SplFileObject" } } } ["previous":"Exception":private]=> NULL }
Output for 5.4.29
object(stdClass)#1 (0) { } object(stdClass)#2 (0) { } Warning: Erroneous data format for unserializing 'ArrayObject' in /in/7DM7S on line 10 Notice: unserialize(): Error at offset 22 of 23 bytes in /in/7DM7S on line 10 bool(false) object(ReflectionException)#1 (7) { ["message":protected]=> string(99) "Class ArrayObject is an internal class that cannot be instantiated without invoking its constructor" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/7DM7S" ["line":protected]=> int(16) ["trace":"Exception":private]=> array(2) { [0]=> array(6) { ["file"]=> string(9) "/in/7DM7S" ["line"]=> int(16) ["function"]=> string(29) "newInstanceWithoutConstructor" ["class"]=> string(15) "ReflectionClass" ["type"]=> string(2) "->" ["args"]=> array(0) { } } [1]=> array(4) { ["file"]=> string(9) "/in/7DM7S" ["line"]=> int(6) ["function"]=> string(46) "instanitateWithoutConstructorThroughReflection" ["args"]=> array(1) { [0]=> string(11) "ArrayObject" } } } ["previous":"Exception":private]=> NULL } Warning: Erroneous data format for unserializing 'SplFileObject' in /in/7DM7S on line 10 Notice: unserialize(): Error at offset 24 of 25 bytes in /in/7DM7S on line 10 bool(false) object(ReflectionException)#2 (7) { ["message":protected]=> string(101) "Class SplFileObject is an internal class that cannot be instantiated without invoking its constructor" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/7DM7S" ["line":protected]=> int(16) ["trace":"Exception":private]=> array(2) { [0]=> array(6) { ["file"]=> string(9) "/in/7DM7S" ["line"]=> int(16) ["function"]=> string(29) "newInstanceWithoutConstructor" ["class"]=> string(15) "ReflectionClass" ["type"]=> string(2) "->" ["args"]=> array(0) { } } [1]=> array(4) { ["file"]=> string(9) "/in/7DM7S" ["line"]=> int(6) ["function"]=> string(46) "instanitateWithoutConstructorThroughReflection" ["args"]=> array(1) { [0]=> string(13) "SplFileObject" } } } ["previous":"Exception":private]=> NULL }
Output for 5.4.0 - 5.4.28
object(stdClass)#1 (0) { } object(stdClass)#2 (0) { } object(ArrayObject)#2 (1) { ["storage":"ArrayObject":private]=> array(0) { } } object(ReflectionException)#1 (7) { ["message":protected]=> string(99) "Class ArrayObject is an internal class that cannot be instantiated without invoking its constructor" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/7DM7S" ["line":protected]=> int(16) ["trace":"Exception":private]=> array(2) { [0]=> array(6) { ["file"]=> string(9) "/in/7DM7S" ["line"]=> int(16) ["function"]=> string(29) "newInstanceWithoutConstructor" ["class"]=> string(15) "ReflectionClass" ["type"]=> string(2) "->" ["args"]=> array(0) { } } [1]=> array(4) { ["file"]=> string(9) "/in/7DM7S" ["line"]=> int(6) ["function"]=> string(46) "instanitateWithoutConstructorThroughReflection" ["args"]=> array(1) { [0]=> string(11) "ArrayObject" } } } ["previous":"Exception":private]=> NULL } object(SplFileObject)#1 (1) { ["pathName":"SplFileInfo":private]=> string(0) "" } object(ReflectionException)#2 (7) { ["message":protected]=> string(101) "Class SplFileObject is an internal class that cannot be instantiated without invoking its constructor" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/7DM7S" ["line":protected]=> int(16) ["trace":"Exception":private]=> array(2) { [0]=> array(6) { ["file"]=> string(9) "/in/7DM7S" ["line"]=> int(16) ["function"]=> string(29) "newInstanceWithoutConstructor" ["class"]=> string(15) "ReflectionClass" ["type"]=> string(2) "->" ["args"]=> array(0) { } } [1]=> array(4) { ["file"]=> string(9) "/in/7DM7S" ["line"]=> int(6) ["function"]=> string(46) "instanitateWithoutConstructorThroughReflection" ["args"]=> array(1) { [0]=> string(13) "SplFileObject" } } } ["previous":"Exception":private]=> NULL }
Output for 5.0.0 - 5.3.29
object(stdClass)#1 (0) { } Fatal error: Call to undefined method ReflectionClass::newInstanceWithoutConstructor() in /in/7DM7S on line 16
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '{' in /in/7DM7S on line 14
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected '{' in /in/7DM7S on line 14
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/7DM7S on line 14
Process exited with code 255.