
ReflectionProperty::isLazy는 속성이 초기화된 상태를 확인하는 메서드입니다. 이 메서드는 속성이 이미 초기화된 경우 true를 반환하고, 초기화되지 않은 경우 false를 반환합니다.
속성을 초기화하는 메서드는 ReflectionProperty::isInitialized입니다. 이 메서드는 속성이 이미 초기화된 경우 true를 반환하고, 초기화되지 않은 경우 false를 반환합니다.
라즈리 로딩을 활성화 또는 비활성화하는 방법은 다음과 같습니다.
#hostingforum.kr
php
use ReflectionClass;
use ReflectionProperty;
class Test {
private $lazyProperty;
public function __construct() {
$this->lazyProperty = null;
}
public function getLazyProperty() {
return $this->lazyProperty;
}
}
$reflectionClass = new ReflectionClass('Test');
$reflectionProperty = $reflectionClass->getProperty('lazyProperty');
// 라즈리 로딩을 활성화합니다.
$reflectionProperty->setAccessible(true);
$reflectionProperty->setLazy(true);
// 라즈리 로딩을 비활성화합니다.
$reflectionProperty->setAccessible(true);
$reflectionProperty->setLazy(false);
// 속성이 초기화된 상태를 확인합니다.
echo var_export($reflectionProperty->isInitialized($reflectionClass->newInstance()), true) . "n"; // false
// 속성을 초기화합니다.
$reflectionClass->newInstance()->getLazyProperty();
// 속성이 초기화된 상태를 다시 확인합니다.
echo var_export($reflectionProperty->isInitialized($reflectionClass->newInstance()), true) . "n"; // true
// 라즈리 로딩 여부를 확인합니다.
echo var_export($reflectionProperty->isLazy($reflectionClass->newInstance()), true) . "n"; // true
위의 예제 코드에서, `ReflectionProperty::isLazy` 메서드는 속성이 이미 초기화된 경우 true를 반환하고, 초기화되지 않은 경우 false를 반환합니다. `ReflectionProperty::isInitialized` 메서드는 속성이 이미 초기화된 경우 true를 반환하고, 초기화되지 않은 경우 false를 반환합니다. `setLazy` 메서드는 라즈리 로딩을 활성화 또는 비활성화합니다.
2025-08-06 04:55