3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foobar implements \Serializable { /** @return string */ public function serialize(): string { return serialize(new \DateTimeZone('Europe/Andorra')); } /** @param string $serialized */ public function unserialize($serialized) { var_dump($serialized); var_dump(unserialize($serialized)->getName()); } } (new Foobar())->unserialize((new Foobar())->serialize()); var_dump(unserialize(serialize(new Foobar())));
Output for 8.1.0 - 8.1.6
Deprecated: Foobar 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/QEdfQ on line 3 string(86) "O:12:"DateTimeZone":2:{s:13:"timezone_type";i:3;s:8:"timezone";s:14:"Europe/Andorra";}" string(14) "Europe/Andorra" string(86) "O:12:"DateTimeZone":2:{s:13:"timezone_type";i:3;s:8:"timezone";s:14:"Europe/Andorra";}" Fatal error: Uncaught Error: The DateTimeZone object has not been correctly initialized by its constructor in /in/QEdfQ:15 Stack trace: #0 /in/QEdfQ(15): DateTimeZone->getName() #1 [internal function]: Foobar->unserialize('O:12:"DateTimeZ...') #2 /in/QEdfQ(20): unserialize('C:6:"Foobar":86...') #3 {main} thrown in /in/QEdfQ on line 15
Process exited with code 255.
Output for 8.0.0 - 8.0.19
string(86) "O:12:"DateTimeZone":2:{s:13:"timezone_type";i:3;s:8:"timezone";s:14:"Europe/Andorra";}" string(14) "Europe/Andorra" string(86) "O:12:"DateTimeZone":2:{s:13:"timezone_type";i:3;s:8:"timezone";s:14:"Europe/Andorra";}" Fatal error: Uncaught Error: The DateTimeZone object has not been correctly initialized by its constructor in /in/QEdfQ:15 Stack trace: #0 /in/QEdfQ(15): DateTimeZone->getName() #1 [internal function]: Foobar->unserialize('O:12:"DateTimeZ...') #2 /in/QEdfQ(20): unserialize('C:6:"Foobar":86...') #3 {main} thrown in /in/QEdfQ on line 15
Process exited with code 255.
Output for 7.0.15 - 7.0.33, 7.1.1 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.29
string(86) "O:12:"DateTimeZone":2:{s:13:"timezone_type";i:3;s:8:"timezone";s:14:"Europe/Andorra";}" string(14) "Europe/Andorra" string(86) "O:12:"DateTimeZone":2:{s:13:"timezone_type";i:3;s:8:"timezone";s:14:"Europe/Andorra";}" Warning: DateTimeZone::getName(): The DateTimeZone object has not been correctly initialized by its constructor in /in/QEdfQ on line 15 bool(false) object(Foobar)#1 (0) { }
Output for 7.0.0 - 7.0.14, 7.1.0
string(86) "O:12:"DateTimeZone":2:{s:13:"timezone_type";i:3;s:8:"timezone";s:14:"Europe/Andorra";}" string(14) "Europe/Andorra" string(86) "O:12:"DateTimeZone":2:{s:13:"timezone_type";i:3;s:8:"timezone";s:14:"Europe/Andorra";}" string(14) "Europe/Andorra" object(Foobar)#1 (0) { }
Output for 5.6.0 - 5.6.40
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/QEdfQ on line 6
Process exited with code 255.

preferences:
52.33 ms | 415 KiB | 5 Q