
getName() 메서드는 ReflectionClassConstant 객체가 참조하는 상수 이름을 반환합니다. 상수 이름이 중복되는 경우, getName() 메서드는 해당 ReflectionClassConstant 객체가 생성된 ReflectionClass 객체의 이름과 상수 이름을 함께 반환합니다. 예를 들어, 동일한 이름의 상수가 여러 클래스에 존재하는 경우, getName() 메서드는 해당 상수의 이름과 생성된 ReflectionClass 객체의 이름을 함께 반환합니다.
예를 들어, 다음 코드를 살펴보겠습니다.
#hostingforum.kr
php
class A {
const X = 10;
}
class B {
const X = 20;
}
$reflectionClassA = new ReflectionClass('A');
$reflectionClassB = new ReflectionClass('B');
$reflectionConstantA = $reflectionClassA->getConstant('X');
$reflectionConstantB = $reflectionClassB->getConstant('X');
echo $reflectionConstantA->getName() . "n"; // A::X
echo $reflectionConstantB->getName() . "n"; // B::X
이 예제에서 getName() 메서드는 각 상수의 이름과 생성된 ReflectionClass 객체의 이름을 함께 반환합니다.
2025-03-23 09:13