
ReflectionAttribute::getTarget는 속성에 대한 정보를 담고 있는 Attribute를 가져오는 메서드입니다. Attribute는 클래스나 메서드에 대한 추가 정보를 제공하는 데 사용됩니다.
클래스의 속성을 얻기 위해서는 ReflectionAttribute::getTarget를 사용하여 Attribute를 가져오고, 그 속성을 통해 클래스의 속성을 얻을 수 있습니다.
예를 들어, 다음 코드는 클래스의 속성을 얻는 방법을 보여줍니다.
#hostingforum.kr
php
use ReflectionClass;
use ReflectionProperty;
class MyClass {
public $myProperty = 'Hello, World!';
}
$reflectionClass = new ReflectionClass('MyClass');
$reflectionProperty = $reflectionClass->getProperty('myProperty');
$attribute = $reflectionProperty->getAttributes()[0];
$target = $attribute->getTarget();
echo $target->getName(); // MyClass
echo $target->getDeclaringClass()->getName(); // MyClass
echo $target->getValue(new MyClass()); // Hello, World!
위 코드에서 ReflectionAttribute::getTarget를 사용하여 MyClass의 myProperty 속성을 얻을 수 있습니다.
2025-07-13 21:50