
ReflectionClass::getInterfaces 메소드는 클래스가 implements 한 첫 번째 인터페이스만 가져옵니다.
다른 인터페이스를 가져오려면, 클래스의 implements 목록을 직접 확인해야 합니다.
예를 들어, 다음과 같은 클래스가 있다고 가정해 보겠습니다.
#hostingforum.kr
php
class MyClass implements Interface1, Interface2, Interface3 {}
이 클래스의 인터페이스를 가져오려면, 다음과 같이 작성할 수 있습니다.
#hostingforum.kr
php
$reflectionClass = new ReflectionClass('MyClass');
$interfaces = $reflectionClass->getInterfaceNames();
foreach ($interfaces as $interface) {
echo $interface . "n";
}
이 코드는 클래스가 implements 한 모든 인터페이스를 가져와 출력합니다.
또한, ReflectionClass::getInterfaceNames 메소드는 인터페이스 이름을 가져오기 때문에, 인터페이스 객체를 가져오려면 ReflectionClass::getInterfaces 메소드를 사용할 수 없습니다.
따라서, 인터페이스 객체를 가져오려면, 다음과 같이 작성할 수 있습니다.
#hostingforum.kr
php
$reflectionClass = new ReflectionClass('MyClass');
$interfaces = $reflectionClass->getInterfaces();
foreach ($interfaces as $interface) {
echo get_class($interface) . "n";
}
이 코드는 클래스가 implements 한 모든 인터페이스의 이름을 가져와 출력합니다.
이러한 방법으로, ReflectionClass::getInterfaces 메소드를 사용하여 인터페이스를 가져올 수 있습니다.
2025-07-21 11:23