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) { $ref = new ReflectionClass($className); return $ref->newInstanceWithoutConstructor(); }
Output for 5.6.0 - 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/HrdHY on line 10 Notice: unserialize(): Error at offset 22 of 23 bytes in /in/HrdHY on line 10 bool(false) object(ArrayObject)#1 (1) { ["storage":"ArrayObject":private]=> array(0) { } } Warning: Erroneous data format for unserializing 'SplFileObject' in /in/HrdHY on line 10 Notice: unserialize(): Error at offset 24 of 25 bytes in /in/HrdHY on line 10 bool(false) object(SplFileObject)#2 (1) { ["pathName":"SplFileInfo":private]=> string(0) "" }
Output for hhvm-3.10.0 - 3.13.2
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.0 - 5.4.28, 5.4.30 - 5.5.12, 5.5.14 - 5.5.38
object(stdClass)#1 (0) { } object(stdClass)#2 (0) { } object(ArrayObject)#2 (1) { ["storage":"ArrayObject":private]=> array(0) { } } Fatal error: Uncaught exception 'ReflectionException' with message 'Class ArrayObject is an internal class that cannot be instantiated without invoking its constructor' in /in/HrdHY:15 Stack trace: #0 /in/HrdHY(15): ReflectionClass->newInstanceWithoutConstructor() #1 /in/HrdHY(6): instanitateWithoutConstructorThroughReflection('ArrayObject') #2 {main} thrown in /in/HrdHY on line 15
Process exited with code 255.
Output for 5.4.29, 5.5.13
object(stdClass)#1 (0) { } object(stdClass)#2 (0) { } Warning: Erroneous data format for unserializing 'ArrayObject' in /in/HrdHY on line 10 Notice: unserialize(): Error at offset 22 of 23 bytes in /in/HrdHY on line 10 bool(false) Fatal error: Uncaught exception 'ReflectionException' with message 'Class ArrayObject is an internal class that cannot be instantiated without invoking its constructor' in /in/HrdHY:15 Stack trace: #0 /in/HrdHY(15): ReflectionClass->newInstanceWithoutConstructor() #1 /in/HrdHY(6): instanitateWithoutConstructorThroughReflection('ArrayObject') #2 {main} thrown in /in/HrdHY on line 15
Process exited with code 255.
Output for 5.0.0 - 5.3.29
object(stdClass)#1 (0) { } Fatal error: Call to undefined method ReflectionClass::newInstanceWithoutConstructor() in /in/HrdHY on line 15
Process exited with code 255.
Output for 4.3.2 - 4.4.9
object(stdClass)(0) { } Fatal error: Cannot instantiate non-existent class: reflectionclass in /in/HrdHY on line 14
Process exited with code 255.
Output for 4.3.0 - 4.3.1
object(stdClass)(0) { } Fatal error: Cannot instantiate non-existent class: reflectionclass in /in/HrdHY on line 14