Skip to content

Commit

Permalink
[Serializer] Fix ObjectNormalizer gives warnings on normalizing wit…
Browse files Browse the repository at this point in the history
…h public static property
  • Loading branch information
alaugks authored and nicolas-grekas committed Oct 3, 2024
1 parent a757250 commit 8be4215
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Normalizer/ObjectNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ protected function isAllowedAttribute($classOrObject, string $attribute, ?string

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

return self::$isReadableCache[$class.$attribute];
Expand Down
10 changes: 10 additions & 0 deletions Tests/Normalizer/ObjectNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,16 @@ public function testDenormalizeWithPropertyPath()

$this->assertEquals($expected, $obj);
}

public function testObjectNormalizerWithAttributeLoaderAndObjectHasStaticProperty()
{
$class = new class {
public static string $foo;
};

$normalizer = new ObjectNormalizer(new ClassMetadataFactory(new AttributeLoader()));
$this->assertSame([], $normalizer->normalize($class));
}
}

class ProxyObjectDummy extends ObjectDummy
Expand Down

0 comments on commit 8be4215

Please sign in to comment.