
네임스페이스를 포함한 인스턴스 변수 이름을 얻으려면, ReflectionClass::getProperties() 메소드의 두 번째 인자 $object에 ReflectionObject를 전달해야 합니다.
예를 들어, 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
class MyClass {
public function __construct() {
$this->Namespace\Variable1 = '값1';
$this->Namespace\Variable2 = '값2';
}
}
$obj = new MyClass();
$reflectionClass = new ReflectionClass('MyClass');
$properties = $reflectionClass->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED | ReflectionProperty::IS_PRIVATE, $obj);
foreach ($properties as $property) {
$propertyName = $property->getName();
echo $propertyName . "n";
}
이 코드를 실행하면, 네임스페이스를 포함한 인스턴스 변수 이름인 Namespace\Variable1과 Namespace\Variable2가 출력됩니다.
2025-04-15 07:52