<?php
class Foo implements \Serializable
{
public $default = 10;
public $setMe;
private $test = 1;
public $removeOnSerialize = 'blah';
public function serialize()
{
unset($this->removeOnSerialze);
return serialize($this->getData());
}
public function unserialize($serialized)
{
foreach (unserialize($serialized) as $key => $value) {
$this->$key = $value;
}
$this->removeOnSerialize = 'Set some value';
}
protected function getData()
{
return (array)$this;
}
}
$obj = new Foo();
$obj->setMe = 9999;
print_r($obj); // here I have all as exepcted
$serialized = serialize($obj);
$unserialized = unserialize($serialized);
print_r($unserialized);
Deprecated: Foo 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/mqijs on line 3
Foo Object
(
[default] => 10
[setMe] => 9999
[test:Foo:private] => 1
[removeOnSerialize] => blah
)
Fatal error: Uncaught Error: Cannot access property starting with "\0" in /in/mqijs:19
Stack trace:
#0 [internal function]: Foo->unserialize('a:4:{s:7:"defau...')
#1 /in/mqijs(37): unserialize('C:3:"Foo":100:{...')
#2 {main}
thrown in /in/mqijs on line 19
Process exited with code 255.
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: Foo 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/mqijs on line 3
Foo Object
(
[default] => 10
[setMe] => 9999
[test:Foo:private] => 1
[removeOnSerialize] => blah
)
Fatal error: Uncaught Error: Cannot access property starting with "\0" in /in/mqijs:19
Stack trace:
#0 [internal function]: Foo->unserialize('a:4:{s:7:"defau...')
#1 /in/mqijs(37): unserialize('C:3:"Foo":100:{...')
#2 {main}
thrown in /in/mqijs on line 19
Process exited with code 255.
Output for 8.0.0 - 8.0.30
Foo Object
(
[default] => 10
[setMe] => 9999
[test:Foo:private] => 1
[removeOnSerialize] => blah
)
Fatal error: Uncaught Error: Cannot access property starting with "\0" in /in/mqijs:19
Stack trace:
#0 [internal function]: Foo->unserialize('a:4:{s:7:"defau...')
#1 /in/mqijs(37): unserialize('C:3:"Foo":100:{...')
#2 {main}
thrown in /in/mqijs on line 19
Process exited with code 255.
Foo Object
(
[default] => 10
[setMe] => 9999
[test:Foo:private] => 1
[removeOnSerialize] => blah
)
Fatal error: Uncaught Error: Cannot access property started with '\0' in /in/mqijs:19
Stack trace:
#0 [internal function]: Foo->unserialize('a:4:{s:7:"defau...')
#1 /in/mqijs(37): unserialize('C:3:"Foo":100:{...')
#2 {main}
thrown in /in/mqijs on line 19
Process exited with code 255.
Output for 5.6.0 - 5.6.24
Foo Object
(
[default] => 10
[setMe] => 9999
[test:Foo:private] => 1
[removeOnSerialize] => blah
)
Fatal error: Cannot access property started with '\0' in /in/mqijs on line 19
Process exited with code 255.