Skip to content

Commit

Permalink
Fixed generic object unserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
sorinsarca committed Dec 25, 2024
1 parent 240fa3c commit 77541aa
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/GenericObjectSerialization.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 77541aa

Please sign in to comment.