
ReflectionMethod::isProtected 메소드는 클래스 내부에서만 접근할 수 있는 protected 메소드를 확인하는 데 사용됩니다.
protected 메소드가 있는지 확인하는 방법은 다음과 같습니다.
1. ReflectionClass 인스턴스를 생성하여 클래스를 분석합니다.
2. ReflectionClass 인스턴스에서 getMethod 메소드를 사용하여 protected 메소드를 찾습니다.
3. ReflectionMethod 인스턴스에서 isProtected 메소드를 사용하여 protected 메소드인지 확인합니다.
예를 들어, 다음 코드에서 protected 메소드가 있는지 확인하는 방법을 보여줍니다.
#hostingforum.kr
php
class ParentClass {
protected function protectedMethod() {}
}
class ChildClass extends ParentClass {
public function test() {
$reflectionClass = new ReflectionClass('ChildClass');
$reflectionMethodProtected = $reflectionClass->getMethod('protectedMethod');
var_dump($reflectionMethodProtected->isProtected()); // bool(true)
}
}
이 코드에서는 ReflectionClass 인스턴스를 생성하여 ChildClass 클래스를 분석한 후, getMethod 메소드를 사용하여 protectedMethod 메소드를 찾습니다. 그리고 ReflectionMethod 인스턴스에서 isProtected 메소드를 사용하여 protected 메소드인지 확인합니다.
2025-05-28 09:59