Skip to content

Commit ff18b68

Browse files
dunglasfabpot
authored andcommitted
[Serializer] Unset object_to_populate after using it
1 parent da655a9 commit ff18b68

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ protected function prepareForDenormalization($data)
279279
* Instantiates an object using constructor parameters when needed.
280280
*
281281
* This method also allows to denormalize data into an existing object if
282-
* it is present in the context with the object_to_populate key.
282+
* it is present in the context with the object_to_populate. This object
283+
* is removed from the context before being returned to avoid side effects
284+
* when recursively normalizing an object graph.
283285
*
284286
* @param array $data
285287
* @param string $class
@@ -298,7 +300,10 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
298300
is_object($context['object_to_populate']) &&
299301
$class === get_class($context['object_to_populate'])
300302
) {
301-
return $context['object_to_populate'];
303+
$object = $context['object_to_populate'];
304+
unset($context['object_to_populate']);
305+
306+
return $object;
302307
}
303308

304309
$constructor = $reflectionClass->getConstructor();

0 commit comments

Comments
 (0)