Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Serializer] Unset object_to_populate after using it
  • Loading branch information
dunglas authored and fabpot committed Jan 12, 2016
1 parent da655a9 commit ff18b68
Showing 1 changed file with 7 additions and 2 deletions.
Expand Up @@ -279,7 +279,9 @@ protected function prepareForDenormalization($data)
* Instantiates an object using constructor parameters when needed.
*
* This method also allows to denormalize data into an existing object if
* it is present in the context with the object_to_populate key.
* it is present in the context with the object_to_populate. This object
* is removed from the context before being returned to avoid side effects
* when recursively normalizing an object graph.
*
* @param array $data
* @param string $class
Expand All @@ -298,7 +300,10 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
is_object($context['object_to_populate']) &&
$class === get_class($context['object_to_populate'])
) {
return $context['object_to_populate'];
$object = $context['object_to_populate'];
unset($context['object_to_populate']);

return $object;
}

$constructor = $reflectionClass->getConstructor();
Expand Down

0 comments on commit ff18b68

Please sign in to comment.