<?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);
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
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.