Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1fafff7

Browse filesBrowse files
alanpoulainfabpot
authored andcommitted
[Serializer] Fix unitialized properties (from PHP 7.4.2) when serializing context for the cache key
1 parent 5da141b commit 1fafff7
Copy full SHA for 1fafff7

File tree

Expand file treeCollapse file tree

2 files changed

+21
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+21
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ protected function createChildContext(array $parentContext, $attribute/*, string
400400
*/
401401
private function getCacheKey($format, array $context)
402402
{
403+
unset($context[self::OBJECT_TO_POPULATE]);
403404
unset($context['cache_key']); // avoid artificially different keys
404405
try {
405406
return md5($format.serialize([

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ public function testDenormalizeStringCollectionDecodedFromXmlWithTwoChildren()
163163
$this->assertEquals('bar', $stringCollection->children[1]);
164164
}
165165

166+
public function testDenormalizeNotSerializableObjectToPopulate()
167+
{
168+
$normalizer = new AbstractObjectNormalizerDummy();
169+
$normalizedData = $normalizer->denormalize(['foo' => 'foo'], Dummy::class, null, [AbstractObjectNormalizer::OBJECT_TO_POPULATE => new NotSerializable()]);
170+
171+
$this->assertSame('foo', $normalizedData->foo);
172+
}
173+
166174
private function getDenormalizerForStringCollection()
167175
{
168176
$extractor = $this->getMockBuilder(PhpDocExtractor::class)->getMock();
@@ -379,3 +387,15 @@ public function setSerializer(SerializerInterface $serializer)
379387
$this->serializer = $serializer;
380388
}
381389
}
390+
391+
class NotSerializable
392+
{
393+
public function __sleep()
394+
{
395+
if (class_exists(\Error::class)) {
396+
throw new \Error('not serializable');
397+
}
398+
399+
throw new \Exception('not serializable');
400+
}
401+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.