From 547e92b2c48d46752fad915b4d74508ab1e69a77 Mon Sep 17 00:00:00 2001 From: Dmytro Dzubenko Date: Thu, 9 Mar 2017 12:38:05 +0200 Subject: [PATCH] Fix unserialization behaviour --- src/Immutable.php | 7 +++++++ test/SerializationTest.php | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 test/SerializationTest.php diff --git a/src/Immutable.php b/src/Immutable.php index c1ff90a..184cfbe 100644 --- a/src/Immutable.php +++ b/src/Immutable.php @@ -55,4 +55,11 @@ final public function __get($name) return $this->_defaultValues[$name]; } + + final public function __wakeup() + { + foreach ($this->_userDefinedProperties as $property => $defined) { + unset($this->{$property}); + } + } } diff --git a/test/SerializationTest.php b/test/SerializationTest.php new file mode 100644 index 0000000..e8fd080 --- /dev/null +++ b/test/SerializationTest.php @@ -0,0 +1,25 @@ +bar = 1; + $foo->baz = 2; + + $serializedValue = serialize($foo); + $deSerializedValue = unserialize($serializedValue); + + $this->assertSame($deSerializedValue->bar, $foo->bar); + $this->assertSame($deSerializedValue->baz, $foo->baz); + } +}