
ReflectionProperty::isPublic 메서드는 클래스의 속성에 대한 접근 권한을 검사하는 데 사용됩니다. 이 메서드는 속성이 public, protected, 또는 private 인지 여부를 boolean 값으로 반환합니다.
예를 들어, 다음과 같은 클래스가 있다고 가정해 보겠습니다.
#hostingforum.kr
php
class User {
private $name;
public $email;
}
이 경우, `ReflectionProperty::isPublic` 메서드를 사용하여 `email` 속성의 접근 권한을 검사하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$reflectionClass = new ReflectionClass('User');
$reflectionProperty = $reflectionClass->getProperty('email');
echo $reflectionProperty->isPublic() ? 'true' : 'false'; // true
위 코드에서 `$reflectionProperty->isPublic()` 메서드는 `email` 속성이 public 인지 여부를 boolean 값으로 반환합니다. 따라서 출력 결과는 `true`가 됩니다.
2025-04-23 08:09