
ReflectionClass::newLazyProxy를 사용하여 객체를 생성한 후, 객체의 속성을 접근할 수 없을 때는 두 가지 경우가 있습니다.
1. 객체의 속성이 private이거나 private final이면, ReflectionClass::newLazyProxy를 사용하여 접근할 수 없습니다.
2. 객체의 속성이 protected이면, ReflectionClass::newLazyProxy를 사용하여 접근할 수 없습니다.
protected 속성을 접근하기 위해서는, ReflectionClass::newLazyProxy를 사용하여 접근할 수 없습니다. 대신, ReflectionClass::newInstance()를 사용하여 객체를 생성한 후, protected 속성을 접근할 수 있습니다.
#hostingforum.kr
php
$reflectionClass = new ReflectionClass('MyClass);
$instance = $reflectionClass->newInstance();
$property = $instance->getProperty('myProperty');
3. private final 속성을 접근하기 위해서는, ReflectionClass::newInstance()를 사용하여 객체를 생성한 후, private final 속성을 접근할 수 없습니다. 대신, private final 속성을 public으로 변경하거나, getter/setter 메소드를 추가하여 접근할 수 있습니다.
#hostingforum.kr
php
class MyClass {
private $myProperty;
public function getMyProperty() {
return $this->myProperty;
}
public function setMyProperty($value) {
$this->myProperty = $value;
}
}
$reflectionClass = new ReflectionClass('MyClass);
$instance = $reflectionClass->newInstance();
$property = $instance->getMyProperty();
$instance->setMyProperty('value');
2025-04-06 15:51