
ReflectionFunctionAbstract::getAttributes 메소드는 PHP의 Reflection클래스에서 사용할 수 있는 메소드입니다. 이 메소드는 함수나 클래스의 속성을 반환합니다.
속성의 의미는 다음과 같습니다.
- name: 속성 이름
- class: 속성이 속한 클래스 이름
- default: 속성의 기본값
- type: 속성의 타입
- visibility: 속성의 접근성
이 메소드를 사용하려면 Reflection클래스의 인스턴스를 생성한 후 getAttributes 메소드를 호출하면 됩니다.
예를 들어, 다음 코드는 Reflection클래스의 인스턴스를 생성하고 getAttributes 메소드를 호출하여 속성을 반환하는 방법을 보여줍니다.
#hostingforum.kr
php
$reflection = new ReflectionClass('MyClass');
$attributes = $reflection->getAttributes();
foreach ($attributes as $attribute) {
echo $attribute->getName() . "n";
echo $attribute->getClass() . "n";
echo $attribute->getDefault() . "n";
echo $attribute->getType() . "n";
echo $attribute->getVisibility() . "n";
}
이 코드는 MyClass 클래스의 속성을 반환하고, 속성의 이름, 클래스 이름, 기본값, 타입, 접근성을 출력합니다.
2025-04-20 19:27