
ReflectionClass::hasProperty는 private, protected, static 프로퍼티를 확인할 때 false를 반환합니다.
private 프로퍼티는 접근 제어자에 따라 보이게 할 수 없습니다.
protected 프로퍼티는 자식 클래스에서 접근할 수 있습니다.
static 프로퍼티는 클래스 이름을 통해 접근할 수 있습니다.
예를 들어, 다음 코드는 private 프로퍼티를 확인할 때 false를 반환합니다.
#hostingforum.kr
php
class Test {
private $privateProperty;
public function __construct() {
$this->privateProperty = 'privateProperty';
}
}
$reflection = new ReflectionClass('Test');
echo var_dump($reflection->hasProperty('privateProperty')); // bool(false)
protected 프로퍼티를 확인할 때는 다음과 같이 접근할 수 있습니다.
#hostingforum.kr
php
class Test {
protected $protectedProperty;
public function __construct() {
$this->protectedProperty = 'protectedProperty';
}
}
class Child extends Test {
}
$reflection = new ReflectionClass('Child');
echo var_dump($reflection->hasProperty('protectedProperty')); // bool(true)
static 프로퍼티를 확인할 때는 다음과 같이 접근할 수 있습니다.
#hostingforum.kr
php
class Test {
public static $staticProperty;
public function __construct() {
self::$staticProperty = 'staticProperty';
}
}
$reflection = new ReflectionClass('Test');
echo var_dump($reflection->hasProperty('staticProperty')); // bool(true)
2025-03-21 15:27