diff --git a/src/GenericObjectSerialization.php b/src/GenericObjectSerialization.php index caed726..49c5ecd 100644 --- a/src/GenericObjectSerialization.php +++ b/src/GenericObjectSerialization.php @@ -49,19 +49,31 @@ public static function unserialize(array &$data, callable $solve, ReflectionClas $solve($object, $data); - foreach ($data as $name => $value) { - if (!$reflection->hasProperty($name)) { - // dynamic - $object->{$name} = $value; - continue; + do { + if (!$data || !$reflection->isUserDefined()) { + break; } + foreach ($data as $name => $value) { + if (!$reflection->hasProperty($name)) { + continue; + } - $property = $reflection->getProperty($name); - if ($property->isStatic()) { - continue; + $property = $reflection->getProperty($name); + if ($property->isStatic()) { + continue; + } + + $property->setAccessible(true); + $property->setValue($object, $value); + unset($data[$name]); + } + } while ($reflection = $reflection->getParentClass()); + + if ($data) { + // dynamic + foreach ($data as $name => $value) { + $object->{$name} = $value; } - $property->setAccessible(true); - $property->setValue($object, $value); } return $object;