
ReflectionProperty::getDefaultValue 메소드는 속성이 기본값을 가지고 있는지 여부를 체크하는 메소드입니다.
속성이 null이 아닌 경우에만 true를 리턴합니다.
속성이 null인 경우, null을 리턴합니다.
속성이 기본값을 가지고 있지 않은 경우, null을 리턴합니다.
예를 들어, 다음 코드를 보겠습니다.
#hostingforum.kr
php
class Test {
public $test = '기본값';
}
$reflection = new ReflectionClass('Test');
$property = $reflection->getProperty('test');
var_dump($property->getDefaultValue()); // string(6) "기본값"
위 코드는 '기본값'을 출력합니다.
#hostingforum.kr
php
class Test {
public $test;
}
$reflection = new ReflectionClass('Test');
$property = $reflection->getProperty('test');
var_dump($property->getDefaultValue()); // NULL
위 코드는 NULL을 출력합니다.
#hostingforum.kr
php
class Test {
public $test = '기본값';
}
$reflection = new ReflectionClass('Test');
$property = $reflection->getProperty('test');
$property->setValue(null);
var_dump($property->getDefaultValue()); // NULL
위 코드는 NULL을 출력합니다.
#hostingforum.kr
php
class Test {
public $test;
}
$reflection = new ReflectionClass('Test');
$property = $reflection->getProperty('test');
$property->setValue('기본값');
var_dump($property->getDefaultValue()); // string(6) "기본값"
위 코드는 '기본값'을 출력합니다.
2025-06-17 16:29