
ReflectionProperty 클래스의 __toString 메서드를 오버라이딩하여 사용하려면, ReflectionProperty 클래스를 상속받은 클래스를 생성하고 __toString 메서드를 오버라이딩해야 합니다.
예를 들어, 다음 코드를 사용할 수 있습니다.
#hostingforum.kr
php
class MyReflectionProperty extends ReflectionProperty {
public function __toString() {
return 'ReflectionProperty [ ' . $this->isPrivate() ? ' ' : ' ' . $this->getName() . ' ]';
}
}
$reflectionClass = new ReflectionClass('MyClass');
$reflectionProperty = $reflectionClass->getProperty('myProperty');
echo (new MyReflectionProperty($reflectionProperty))->__toString();
이 코드는 ReflectionProperty 클래스를 상속받은 MyReflectionProperty 클래스를 생성하고, __toString 메서드를 오버라이딩하여 ReflectionProperty 객체의 정보를 문자열로 출력합니다.
이 코드를 사용하면, 원하는 결과를 얻을 수 있습니다.
#hostingforum.kr
php
ReflectionProperty [ public $myProperty ]
2025-07-29 00:17