Skip to content

Commit 67f49d4

Browse files
committed
Fix order array sum normalizedData and nestedData
Previously, when `array_merge` was changed array+array in 6.3.5, the combined array result is changed as well. array_merge behaves differently than array+array. e.g.: ``` $a = ['key' => 'value-a']; $b = ['key' => 'value-b']; var_dump(array_merge($a, $b)); // Results in: // array(1) { // ["key"]=> // string(7) "value-b" // } var_dump($a + $b); // Results in: // array(1) { // ["key"]=> // string(7) "value-a" // } ``` By switching left with right, the result will be the same again.
1 parent 7aa60d6 commit 67f49d4

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public function denormalize(mixed $data, string $type, string $format = null, ar
339339
$normalizedData = $this->removeNestedValue($serializedPath->getElements(), $normalizedData);
340340
}
341341

342-
$normalizedData = $normalizedData + $nestedData;
342+
$normalizedData = $nestedData + $normalizedData;
343343

344344
$object = $this->instantiateObject($normalizedData, $mappedClass, $context, new \ReflectionClass($mappedClass), $allowedAttributes, $format);
345345
$resolvedClass = ($this->objectClassResolver)($object);

src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,28 @@ public function testDenormalizeWithNumberAsSerializedNameAndNoArrayReindex()
813813
$this->assertSame('foo', $test->foo);
814814
$this->assertSame('baz', $test->baz);
815815
}
816+
817+
public function testDenormalizeWithCorrectOrderOfAttributeAndProperty()
818+
{
819+
$normalizer = new AbstractObjectNormalizerWithMetadata();
820+
821+
$data = [
822+
'id' => 'root-level-id',
823+
'data' => [
824+
'id' => 'nested-id',
825+
],
826+
];
827+
828+
$obj = new class() {
829+
/**
830+
* @SerializedPath("[data][id]")
831+
*/
832+
public $id;
833+
};
834+
835+
$test = $normalizer->denormalize($data, $obj::class);
836+
$this->assertSame('nested-id', $test->id);
837+
}
816838
}
817839

818840
class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy