
ReflectionClass::getMethods 메서드는 클래스의 메서드를 가져올 때, 상속받은 메서드도 함께 가져옵니다.
예를 들어, ParentClass가 ChildClass를 상속받았다면, ReflectionClass::getMethods를 사용하여 ChildClass의 메서드를 가져왔을 때, ParentClass의 메서드도 함께 가져옵니다.
이러한 문제가 발생하는 이유는 ReflectionClass::getMethods 메서드는 클래스의 메서드를 가져올 때, 상속받은 메서드까지 포함하여 가져오기 때문입니다.
이러한 문제를 해결하기 위해서는, 상속받은 메서드를 제외하고 싶을 때, ReflectionClass::getMethods 메서드의 인자로 $withPrivate = false, $withPublic = true, $withProtected = false, $withInternal = false를 설정하면 됩니다.
예를 들어, 다음과 같이 설정할 수 있습니다.
#hostingforum.kr
php
$reflectionClass = new ReflectionClass('ChildClass');
$methods = $reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC);
위의 코드는 ChildClass의 public 메서드만 가져옵니다.
또한, ReflectionClass::getMethods 메서드의 인자로 ReflectionMethod::IS_PUBLIC, ReflectionMethod::IS_PROTECTED, ReflectionMethod::IS_PRIVATE, ReflectionMethod::IS_ABSTRACT, ReflectionMethod::IS_FINAL을 설정할 수 있습니다.
이러한 인자들은 메서드의 접근 제어자에 따라 메서드를 가져올 수 있습니다.
예를 들어, 다음과 같이 설정할 수 있습니다.
#hostingforum.kr
php
$reflectionClass = new ReflectionClass('ChildClass');
$methods = $reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED);
위의 코드는 ChildClass의 public 및 protected 메서드만 가져옵니다.
이러한 인자는 메서드의 접근 제어자에 따라 메서드를 가져올 수 있습니다.
이러한 문제를 해결하기 위해서는, ReflectionClass::getMethods 메서드의 인자를 설정하여 메서드를 가져올 수 있습니다.
2025-04-22 16:07