
ReflectionMethod::isPublic 메서드는 메서드가 public 이지만, 클래스의 private 멤버 변수를 접근하는 경우 false를 반환할 수 있습니다.
이 문제를 해결하려면, ReflectionClass::getMethods 메서드를 사용하여 클래스의 모든 메서드를 가져와, 해당 메서드가 public 인지 확인하는 방식으로 접근할 수 있습니다.
예를 들어, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
php
$reflectionClass = new ReflectionClass('MyClass');
$methods = $reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC);
foreach ($methods as $method) {
if ($method->getName() == 'myMethod') {
var_dump($method->isPublic()); // bool(true)
}
}
또는, ReflectionClass::getMethods 메서드의 두 번째 인자로 ReflectionMethod::IS_PUBLIC을 지정하여, 클래스의 public 메서드만 가져와 확인할 수 있습니다.
#hostingforum.kr
php
$reflectionClass = new ReflectionClass('MyClass');
$methods = $reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC);
foreach ($methods as $method) {
var_dump($method->isPublic()); // bool(true)
}
2025-04-06 19:23