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); + } +}