diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php index 554f36c585..b431a17401 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php @@ -279,7 +279,9 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N * 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 @@ -298,7 +300,10 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N 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();