
ReflectionClass::isProtected 메소드는 클래스 상수가 protected 접근 제어자로 선언되었는지 확인합니다.
이 메소드는 클래스 상수가 protected 접근 제어자로 선언되었을 때 true를 반환하고, 그렇지 않은 경우 false를 반환합니다.
예시 코드:
#hostingforum.kr
php
use ReflectionClass;
class MyClass {
public const MY_PUBLIC_CONSTANT = 'public';
protected const MY_PROTECTED_CONSTANT = 'protected';
private const MY_PRIVATE_CONSTANT = 'private';
}
$reflectionClass = new ReflectionClass(MyClass::class);
echo var_dump($reflectionClass->getConstant('MY_PUBLIC_CONSTANT')->isProtected()) . "n"; // false
echo var_dump($reflectionClass->getConstant('MY_PROTECTED_CONSTANT')->isProtected()) . "n"; // true
echo var_dump($reflectionClass->getConstant('MY_PRIVATE_CONSTANT')->isProtected()) . "n"; // false
위 예시 코드에서, MY_PUBLIC_CONSTANT은 public 접근 제어자로 선언되어 있으므로 isProtected 메소드는 false를 반환합니다. MY_PROTECTED_CONSTANT은 protected 접근 제어자로 선언되어 있으므로 isProtected 메소드는 true를 반환합니다. MY_PRIVATE_CONSTANT은 private 접근 제어자로 선언되어 있으므로 isProtected 메소드는 false를 반환합니다.
2025-03-11 12:43