<?php
class child implements Serializable
{
public function serialize()
{
return null;
}
public function unserialize($serialized)
{
}
}
class test
{
private $elems = [];
public function add($something)
{
$this->elems[] = $something;
}
}
$child = new child();
$t = new test();
$t->add(1);
$t->add('test');
var_dump(unserialize(serialize($t)));
$t->add($child);
var_dump(unserialize(serialize($t)));
$t->add($child);
var_dump(unserialize(serialize($t)));
Deprecated: child 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/cTPe9 on line 3
object(test)#3 (1) {
["elems":"test":private]=>
array(2) {
[0]=>
int(1)
[1]=>
string(4) "test"
}
}
object(test)#3 (1) {
["elems":"test":private]=>
array(3) {
[0]=>
int(1)
[1]=>
string(4) "test"
[2]=>
NULL
}
}
object(test)#3 (1) {
["elems":"test":private]=>
array(4) {
[0]=>
int(1)
[1]=>
string(4) "test"
[2]=>
NULL
[3]=>
NULL
}
}
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
Deprecated: child 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/cTPe9 on line 3
object(test)#3 (1) {
["elems":"test":private]=>
array(2) {
[0]=>
int(1)
[1]=>
string(4) "test"
}
}
object(test)#3 (1) {
["elems":"test":private]=>
array(3) {
[0]=>
int(1)
[1]=>
string(4) "test"
[2]=>
NULL
}
}
object(test)#3 (1) {
["elems":"test":private]=>
array(4) {
[0]=>
int(1)
[1]=>
string(4) "test"
[2]=>
NULL
[3]=>
NULL
}
}