
ReflectionProperty::getAttributes 메소드는 ReflectionAttribute[] 타입의 값을 반환합니다.
ReflectionAttribute는 클래스의 속성을 반영하는 데 사용되는 속성의 정보를 포함하는 클래스입니다.
예를 들어, 클래스에 @property 어노테이션을 사용하여 속성을 정의한 경우, ReflectionAttribute를 통해 속성의 정보를 가져올 수 있습니다.
예시:
#hostingforum.kr
php
class MyClass {
/**
* @property int $myProperty
*/
public $myProperty;
}
$reflectionClass = new ReflectionClass('MyClass');
$reflectionProperty = $reflectionClass->getProperty('myProperty');
$attributes = $reflectionProperty->getAttributes();
foreach ($attributes as $attribute) {
echo $attribute->getName() . "n";
echo $attribute->getTarget() . "n";
}
위 예시에서는 MyClass 클래스의 myProperty 속성에 대한 ReflectionAttribute를 가져와 이름과 타겟을 출력합니다.
이러한 방법으로 ReflectionProperty::getAttributes 메소드를 사용하여 클래스의 속성을 반영할 수 있습니다.
2025-06-05 20:14