<?php
class A {
public $x;
public function __construct() {
$this->x = 1;
}
public function __sleep() {
return [ 'x', '' ];
}
}
$a = new A;
var_dump( unserialize( serialize( $a ) ) );
Warning: serialize(): "" returned as member variable from __sleep() but does not exist in /in/9KgXc on line 17
object(A)#2 (1) {
["x"]=>
int(1)
}
Output for 8.3.5
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
Warning: serialize(): "" returned as member variable from __sleep() but does not exist in /in/9KgXc on line 17
object(A)#2 (1) {
["x"]=>
int(1)
}
Notice: serialize(): "" returned as member variable from __sleep() but does not exist in /in/9KgXc on line 17
object(A)#2 (2) {
["x"]=>
int(1)
[""]=>
NULL
}