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 bcc38d9

Browse filesBrowse files
alaugksnicolas-grekas
authored andcommitted
[Serializer] Fix ObjectNormalizer gives warnings on normalizing with public static property
1 parent 2de4387 commit bcc38d9
Copy full SHA for bcc38d9

File tree

2 files changed

+11
-1
lines changed
Filter options

2 files changed

+11
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ protected function isAllowedAttribute($classOrObject, string $attribute, ?string
197197

198198
if ($context['_read_attributes'] ?? true) {
199199
if (!isset(self::$isReadableCache[$class.$attribute])) {
200-
self::$isReadableCache[$class.$attribute] = (\is_object($classOrObject) && $this->propertyAccessor->isReadable($classOrObject, $attribute)) || $this->propertyInfoExtractor->isReadable($class, $attribute) || $this->hasAttributeAccessorMethod($class, $attribute);
200+
self::$isReadableCache[$class.$attribute] = $this->propertyInfoExtractor->isReadable($class, $attribute) || $this->hasAttributeAccessorMethod($class, $attribute) || (\is_object($classOrObject) && $this->propertyAccessor->isReadable($classOrObject, $attribute));
201201
}
202202

203203
return self::$isReadableCache[$class.$attribute];

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,16 @@ public function testDenormalizeWithPropertyPath()
927927

928928
$this->assertEquals($expected, $obj);
929929
}
930+
931+
public function testObjectNormalizerWithAttributeLoaderAndObjectHasStaticProperty()
932+
{
933+
$class = new class {
934+
public static string $foo;
935+
};
936+
937+
$normalizer = new ObjectNormalizer(new ClassMetadataFactory(new AttributeLoader()));
938+
$this->assertSame([], $normalizer->normalize($class));
939+
}
930940
}
931941

932942
class ProxyObjectDummy extends ObjectDummy

0 commit comments

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