
ReflectionAttribute::getName 메서드는 Attribute 이름을 가져올 때, 문자열 형식으로 값을 반환합니다.
예를 들어, Attribute에 이름이 "MyAttribute"인 경우, getName 메서드는 "MyAttribute"라는 문자열을 반환합니다.
이 메서드는 Attribute의 이름을 가져올 때 사용되는 메서드이므로, Attribute 이름이 잘못된 경우, 잘못된 값을 반환할 수 있습니다.
따라서 Attribute 이름을 가져올 때, getName 메서드를 사용하기 전에 Attribute 이름이 올바른지 확인하는 것이 중요합니다.
예를 들어, Attribute에 이름이 "MyAttribute"인 경우, getName 메서드는 "MyAttribute"라는 문자열을 반환합니다.
#hostingforum.kr
php
use ReflectionClass;
use ReflectionAttribute;
class MyClass {
#[MyAttribute]
public function myMethod() {}
}
$reflectionClass = new ReflectionClass(MyClass::class);
$reflectionAttribute = $reflectionClass->getMethod('myMethod')->getAttributes()[0];
echo $reflectionAttribute->getName(); // MyAttribute
2025-06-25 22:13