
ReflectionProperty::setValue 메소드는 객체가 이미 생성되어 있어야만 작동합니다. 객체가 아직 생성되지 않았을 때, ReflectionProperty::setValue 메소드는 예외를 발생시키지 않습니다. 대신, 객체의 속성을 설정하지 못합니다.
예를 들어, 아래와 같은 코드는 객체가 이미 생성되어 있어야만 작동합니다.
#hostingforum.kr
php
$reflection = new ReflectionClass('Test');
$property = $reflection->getProperty('test');
$property->setAccessible(true);
$property->setValue($reflection->newInstance(), 'new_value');
객체가 아직 생성되지 않았을 때, 아래와 같은 코드는 예외를 발생시키지 않습니다.
#hostingforum.kr
php
$reflection = new ReflectionClass('Test');
$property = $reflection->getProperty('test');
$property->setAccessible(true);
$property->setValue(null, 'new_value');
객체가 아직 생성되지 않았을 때, ReflectionProperty::setValue 메소드는 객체의 속성을 설정하지 못합니다. 객체를 생성한 후에 ReflectionProperty::setValue 메소드를 사용하여 객체의 속성을 설정해야 합니다.
2025-07-12 08:47