3v4l.org

run code in 300+ PHP versions simultaneously
<?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); $inst = $ref->newInstanceWithoutConstructor(); } catch (ReflectionException $e) { return $e; } }
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
object(stdClass)#1 (0) { } NULL Fatal error: Uncaught UnexpectedValueException: Incomplete or ill-typed serialization data in /in/91fZf:10 Stack trace: #0 [internal function]: ArrayObject->__unserialize(Array) #1 /in/91fZf(10): unserialize('O:11:"ArrayObje...') #2 /in/91fZf(5): instanitateWithoutConstructorThroughUnserialize('ArrayObject') #3 {main} thrown in /in/91fZf on line 10
Process exited with code 255.
Output for 7.3.32 - 7.3.33
object(stdClass)#1 (0) { } NULL Warning: Erroneous data format for unserializing 'ArrayObject' in /in/91fZf on line 10 bool(false) NULL Warning: Erroneous data format for unserializing 'SplFileObject' in /in/91fZf on line 10 bool(false) NULL
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31
object(stdClass)#1 (0) { } NULL Warning: Erroneous data format for unserializing 'ArrayObject' in /in/91fZf on line 10 Notice: unserialize(): Error at offset 22 of 23 bytes in /in/91fZf on line 10 bool(false) NULL Warning: Erroneous data format for unserializing 'SplFileObject' in /in/91fZf on line 10 Notice: unserialize(): Error at offset 24 of 25 bytes in /in/91fZf on line 10 bool(false) NULL
Output for 5.4.30 - 5.4.45, 5.5.14 - 5.5.38
object(stdClass)#1 (0) { } NULL 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/91fZf" ["line":protected]=> int(16) ["trace":"Exception":private]=> array(2) { [0]=> array(6) { ["file"]=> string(9) "/in/91fZf" ["line"]=> int(16) ["function"]=> string(29) "newInstanceWithoutConstructor" ["class"]=> string(15) "ReflectionClass" ["type"]=> string(2) "->" ["args"]=> array(0) { } } [1]=> array(4) { ["file"]=> string(9) "/in/91fZf" ["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/91fZf on line 10 Notice: unserialize(): Error at offset 24 of 25 bytes in /in/91fZf 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/91fZf" ["line":protected]=> int(16) ["trace":"Exception":private]=> array(2) { [0]=> array(6) { ["file"]=> string(9) "/in/91fZf" ["line"]=> int(16) ["function"]=> string(29) "newInstanceWithoutConstructor" ["class"]=> string(15) "ReflectionClass" ["type"]=> string(2) "->" ["args"]=> array(0) { } } [1]=> array(4) { ["file"]=> string(9) "/in/91fZf" ["line"]=> int(6) ["function"]=> string(46) "instanitateWithoutConstructorThroughReflection" ["args"]=> array(1) { [0]=> string(13) "SplFileObject" } } } ["previous":"Exception":private]=> NULL }
Output for 5.4.29, 5.5.13
object(stdClass)#1 (0) { } NULL Warning: Erroneous data format for unserializing 'ArrayObject' in /in/91fZf on line 10 Notice: unserialize(): Error at offset 22 of 23 bytes in /in/91fZf 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/91fZf" ["line":protected]=> int(16) ["trace":"Exception":private]=> array(2) { [0]=> array(6) { ["file"]=> string(9) "/in/91fZf" ["line"]=> int(16) ["function"]=> string(29) "newInstanceWithoutConstructor" ["class"]=> string(15) "ReflectionClass" ["type"]=> string(2) "->" ["args"]=> array(0) { } } [1]=> array(4) { ["file"]=> string(9) "/in/91fZf" ["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/91fZf on line 10 Notice: unserialize(): Error at offset 24 of 25 bytes in /in/91fZf 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/91fZf" ["line":protected]=> int(16) ["trace":"Exception":private]=> array(2) { [0]=> array(6) { ["file"]=> string(9) "/in/91fZf" ["line"]=> int(16) ["function"]=> string(29) "newInstanceWithoutConstructor" ["class"]=> string(15) "ReflectionClass" ["type"]=> string(2) "->" ["args"]=> array(0) { } } [1]=> array(4) { ["file"]=> string(9) "/in/91fZf" ["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, 5.5.0 - 5.5.12
object(stdClass)#1 (0) { } NULL 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/91fZf" ["line":protected]=> int(16) ["trace":"Exception":private]=> array(2) { [0]=> array(6) { ["file"]=> string(9) "/in/91fZf" ["line"]=> int(16) ["function"]=> string(29) "newInstanceWithoutConstructor" ["class"]=> string(15) "ReflectionClass" ["type"]=> string(2) "->" ["args"]=> array(0) { } } [1]=> array(4) { ["file"]=> string(9) "/in/91fZf" ["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/91fZf" ["line":protected]=> int(16) ["trace":"Exception":private]=> array(2) { [0]=> array(6) { ["file"]=> string(9) "/in/91fZf" ["line"]=> int(16) ["function"]=> string(29) "newInstanceWithoutConstructor" ["class"]=> string(15) "ReflectionClass" ["type"]=> string(2) "->" ["args"]=> array(0) { } } [1]=> array(4) { ["file"]=> string(9) "/in/91fZf" ["line"]=> int(6) ["function"]=> string(46) "instanitateWithoutConstructorThroughReflection" ["args"]=> array(1) { [0]=> string(13) "SplFileObject" } } } ["previous":"Exception":private]=> NULL }
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
object(stdClass)#1 (0) { } Fatal error: Call to undefined method ReflectionClass::newInstanceWithoutConstructor() in /in/91fZf on line 16
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '{' in /in/91fZf on line 14
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected '{' in /in/91fZf on line 14
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/91fZf on line 14
Process exited with code 255.

preferences:
290.32 ms | 401 KiB | 457 Q