[Serializer] Unset object_to_populate after using it

This commit is contained in:
Kévin Dunglas 2016-01-06 07:50:20 +01:00 committed by Fabien Potencier
parent da655a9368
commit ff18b68e77

View File

@ -279,7 +279,9 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
* Instantiates an object using constructor parameters when needed. * Instantiates an object using constructor parameters when needed.
* *
* This method also allows to denormalize data into an existing object if * 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 array $data
* @param string $class * @param string $class
@ -298,7 +300,10 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
is_object($context['object_to_populate']) && is_object($context['object_to_populate']) &&
$class === get_class($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(); $constructor = $reflectionClass->getConstructor();