Skip to content

Commit 0096175

Browse files
committed
bug symfony#48978 [Serializer] use method_exists() instead of catching reflection exceptions (xabbuh)
This PR was merged into the 5.4 branch. Discussion ---------- [Serializer] use method_exists() instead of catching reflection exceptions | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | symfony#48233 (comment) | License | MIT | Doc PR | Commits ------- 0e883a9 use method_exists() instead of catching reflection exceptions
2 parents 3ca58ba + 0e883a9 commit 0096175

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,7 @@ protected function setAttributeValue(object $object, string $attribute, $value,
152152
$key = \get_class($object).':'.$setter;
153153

154154
if (!isset(self::$setterAccessibleCache[$key])) {
155-
try {
156-
// We have to use is_callable() here since method_exists()
157-
// does not "see" protected/private methods
158-
self::$setterAccessibleCache[$key] = \is_callable([$object, $setter]) && !(new \ReflectionMethod($object, $setter))->isStatic();
159-
} catch (\ReflectionException $e) {
160-
// Method does not exist in the class, probably a magic method
161-
self::$setterAccessibleCache[$key] = false;
162-
}
155+
self::$setterAccessibleCache[$key] = method_exists($object, $setter) && \is_callable([$object, $setter]) && !(new \ReflectionMethod($object, $setter))->isStatic();
163156
}
164157

165158
if (self::$setterAccessibleCache[$key]) {

0 commit comments

Comments
 (0)