diff --git a/src/Reflection/ClassReflection.php b/src/Reflection/ClassReflection.php index 02705f32cd..d031cb8816 100644 --- a/src/Reflection/ClassReflection.php +++ b/src/Reflection/ClassReflection.php @@ -142,6 +142,9 @@ class ClassReflection /** @var array */ private static array $resolvingTypeAliasImports = []; + /** @var array */ + private array $hasMethodCache = []; + /** * @param PropertiesClassReflectionExtension[] $propertiesClassReflectionExtensions * @param MethodsClassReflectionExtension[] $methodsClassReflectionExtensions @@ -482,16 +485,26 @@ public function hasProperty(string $propertyName): bool public function hasMethod(string $methodName): bool { + if (array_key_exists($methodName, $this->hasMethodCache)) { + return $this->hasMethodCache[$methodName]; + } + foreach ($this->methodsClassReflectionExtensions as $extension) { if ($extension->hasMethod($this, $methodName)) { + $this->hasMethodCache[$methodName] = true; + return true; } } if ($this->requireExtendsMethodsClassReflectionExtension->hasMethod($this, $methodName)) { + $this->hasMethodCache[$methodName] = true; + return true; } + $this->hasMethodCache[$methodName] = false; + return false; }