diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php index 554f36c585809..b431a17401945 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php @@ -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 @@ -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();
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: