
ReflectionProperty::isInitialized 함수는 객체의 속성이 초기화되었는지 여부를 확인하는 함수입니다.
이 함수는 객체의 속성이 초기화되었는지 여부를 확인하기 위해, 객체의 속성이 생성자에서 초기화되었는지 여부를 확인합니다.
만약, 객체의 속성이 생성자에서 초기화되었다면 true를 반환하고, 초기화되지 않았다면 false를 반환합니다.
예를 들어, 다음 코드를 살펴보겠습니다.
#hostingforum.kr
php
class Person {
public $name;
public $age;
function __construct($name, $age) {
$this->name = $name;
$this->age = $age;
}
}
$person = new Person('John', 30);
$reflectionProperty = new ReflectionProperty('Person', 'name');
echo ReflectionProperty::isInitialized($reflectionProperty) ? 'true' : 'false'; // true
$reflectionProperty = new ReflectionProperty('Person', 'age');
echo ReflectionProperty::isInitialized($reflectionProperty) ? 'true' : 'false'; // true
$reflectionProperty = new ReflectionProperty('Person', 'sex');
echo ReflectionProperty::isInitialized($reflectionProperty) ? 'true' : 'false'; // false
위 코드에서, 'name'과 'age' 속성은 생성자에서 초기화되었기 때문에 true를 반환합니다. 하지만 'sex' 속성은 초기화되지 않았기 때문에 false를 반환합니다.
2025-08-15 02:37