3v4l.org

run code in 300+ PHP versions simultaneously
<?php $classNames = array( "Foo", // userland class "StdClass", // class defined by php-src, but still not considered as internal "Bar", // userland class implementing Serializable "ReflectionClass", // internal class "ArrayObject", // internal class implementing Serializable "Baz", // userland class extending internal class implementing Serializable ); 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; } } class Foo {} class Bar implements Serializable { private $data; public function serialize() { return serialize($this->data); } public function unserialize($data) { $this->data = unserialize($data); } } class Baz extends ArrayObject {} foreach($classNames as $className) { echo "$className\n"; var_dump(instanitateWithoutConstructorThroughUnserialize($className)); if (version_compare(PHP_VERSION, '5.4.0') >= 0) { var_dump(instanitateWithoutConstructorThroughReflection($className)); } echo "\n"; }
Output for git.master, git.master_jit
Deprecated: Bar implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /in/mL7kC on line 27 Foo object(Foo)#1 (0) { } object(Foo)#2 (0) { } StdClass object(stdClass)#2 (0) { } object(stdClass)#1 (0) { } Bar Warning: Erroneous data format for unserializing 'Bar' in /in/mL7kC on line 13 Notice: unserialize(): Error at offset 13 of 14 bytes in /in/mL7kC on line 13 bool(false) object(Bar)#2 (1) { ["data":"Bar":private]=> NULL } ReflectionClass Fatal error: Uncaught Exception: Unserialization of 'ReflectionClass' is not allowed in /in/mL7kC:13 Stack trace: #0 /in/mL7kC(13): unserialize('O:15:"Reflectio...') #1 /in/mL7kC(43): instanitateWithoutConstructorThroughUnserialize('ReflectionClass') #2 {main} thrown in /in/mL7kC on line 13
Process exited with code 255.
Output for rfc.property-hooks
Deprecated: Bar implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /in/mL7kC on line 27 Foo object(Foo)#1 (0) { } object(Foo)#2 (0) { } StdClass object(stdClass)#2 (0) { } object(stdClass)#1 (0) { } Bar Warning: Erroneous data format for unserializing 'Bar' in /in/mL7kC on line 13 Warning: unserialize(): Error at offset 13 of 14 bytes in /in/mL7kC on line 13 bool(false) object(Bar)#2 (1) { ["data":"Bar":private]=> NULL } ReflectionClass Fatal error: Uncaught Exception: Unserialization of 'ReflectionClass' is not allowed in /in/mL7kC:13 Stack trace: #0 /in/mL7kC(13): unserialize('O:15:"Reflectio...') #1 /in/mL7kC(43): instanitateWithoutConstructorThroughUnserialize('ReflectionClass') #2 {main} thrown in /in/mL7kC on line 13
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
48.75 ms | 402 KiB | 8 Q