<?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);
}
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/M3805 on line 3
Foo Object
(
[default] => 10
[setMe] => 9999
[test:Foo:private] => 1
[removeOnSerialize] => blah
)
Foo Object
(
[default] => 10
[setMe] =>
[test:Foo:private] => 1
[removeOnSerialize] => Set some value
)