
ReflectionMethod 클래스의 isProtected 메서드는 protected 키워드가 사용된 메서드인지 아닌지를 확인하는 데 사용됩니다.
protected 키워드는 메서드의 접근 레벨을 지정하는 데 사용되며, 해당 클래스의 자식 클래스에서 접근할 수 있도록 허용합니다.
isProtected 메서드는 메서드의 이름을 통해 protected 키워드가 사용된 경우 true를 반환하고, 그렇지 않은 경우 false를 반환합니다.
이 메서드는 PHPDoc의 @protected 태그나 PHP의 protected 키워드가 사용된 메서드의 이름을 통해 protected 키워드가 사용된 경우를 확인합니다.
예를 들어, 다음 코드는 protected 키워드가 사용된 메서드인 경우 true를 반환합니다.
#hostingforum.kr
php
class ParentClass {
protected function protectedMethod() {}
}
class ChildClass extends ParentClass {
public function test() {
$reflectionMethod = new ReflectionMethod('ChildClass', 'test');
$isProtected = $reflectionMethod->isProtected();
var_dump($isProtected); // bool(true)
}
}
반면에, 다음 코드는 protected 키워드가 사용되지 않은 메서드인 경우 false를 반환합니다.
#hostingforum.kr
php
class ParentClass {
public function publicMethod() {}
}
class ChildClass extends ParentClass {
public function test() {
$reflectionMethod = new ReflectionMethod('ChildClass', 'test');
$isProtected = $reflectionMethod->isProtected();
var_dump($isProtected); // bool(false)
}
}
2025-08-02 16:29