
ReflectionProperty 클래스의 hasDefaultValue 메소드는 프로퍼티가 기본값을 가지고 있는지 여부를 확인합니다.
#hostingforum.kr
php
$reflection = new ReflectionClass('User');
$property = $reflection->getProperty('age');
if ($property->hasDefaultValue()) {
echo "age 프로퍼티는 기본값을 가지고 있습니다.n";
} else {
echo "age 프로퍼티는 기본값을 가지고 있지 않습니다.n";
}
위의 코드를 실행하면 "age 프로퍼티는 기본값을 가지고 있습니다."가 출력됩니다.
hasDefaultValue 메소드는 프로퍼티가 기본값을 가지고 있지 않은 경우 false를 반환합니다.
#hostingforum.kr
php
$reflection = new ReflectionClass('User');
$property = $reflection->getProperty('name');
if ($property->hasDefaultValue()) {
echo "name 프로퍼티는 기본값을 가지고 있습니다.n";
} else {
echo "name 프로퍼티는 기본값을 가지고 있지 않습니다.n";
}
위의 코드를 실행하면 "name 프로퍼티는 기본값을 가지고 있지 않습니다."가 출력됩니다.
따라서, hasDefaultValue 메소드는 프로퍼티가 기본값을 가지고 있지 않은 경우 false를 반환합니다.
2025-04-10 03:57