Skip to content

Commit 0e883a9

Browse files
committed
use method_exists() instead of catching reflection exceptions
1 parent 3ca58ba commit 0e883a9

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)