3v4l.org

run code in 300+ PHP versions simultaneously
<?php class HasProp { public int $x; public function __sleep() { return ['x']; } } $x = new HasProp(); // string(28) "O:7:"HasProp":1:{s:1:"x";N;}" var_dump($s = serialize($x)); // Fatal error: Uncaught TypeError: Typed property HasProp::$x must be int, null used in ... unserialize($s);
Output for 7.4.6 - 7.4.30, 8.0.0 - 8.0.22, 8.1.0 - 8.1.9
string(18) "O:7:"HasProp":0:{}"
Output for 7.4.2 - 7.4.5
Fatal error: Uncaught Error: Typed property HasProp::$x must not be accessed before initialization (in __sleep) in /in/PCLm3:8 Stack trace: #0 /in/PCLm3(8): serialize(Object(HasProp)) #1 {main} thrown in /in/PCLm3 on line 8
Process exited with code 255.
Output for 7.4.0 - 7.4.1
Notice: serialize(): "x" returned as member variable from __sleep() but does not exist in /in/PCLm3 on line 8 string(28) "O:7:"HasProp":1:{s:1:"x";N;}" Fatal error: Uncaught TypeError: Typed property HasProp::$x must be int, null used in /in/PCLm3:10 Stack trace: #0 /in/PCLm3(10): unserialize('O:7:"HasProp":1...') #1 {main} thrown in /in/PCLm3 on line 10
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Parse error: syntax error, unexpected 'int' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /in/PCLm3 on line 3
Process exited with code 255.

preferences:
59.27 ms | 413 KiB | 5 Q