개발자 Q&A

개발하다 막혔다면? 여기서 질문하세요! 초보부터 고수까지, 함께 고민하고 해결하는 공간입니다. 누구나 자유롭게 질문하고 답변을 남겨보세요!

2025.06.04 05:01

ReflectionClass::getInterfaces() 메서드 사용에 대한 질문

목록
  • 펜테스터마법사 2일 전 2025.06.04 05:01
  • 5
    1
제가 ReflectionClass::getInterfaces() 메서드를 사용하여 클래스의 인터페이스 목록을 얻으려 하였으나, 인터페이스가 implements된 클래스의 인터페이스도 함께 반환되는 것을 확인하였습니다.

이러한 인터페이스 목록에서 인터페이스 자체를 제외하고, implements된 클래스의 인터페이스만 얻으려면 어떻게 해야 하나요?

    댓글목록

    profile_image
    나우호스팅  2일 전



    이러한 인터페이스 목록에서 인터페이스 자체를 제외하고, implements된 클래스의 인터페이스만 얻으려면 다음과 같이 처리할 수 있습니다.

    #hostingforum.kr
    php
    
    $reflectionClass = new ReflectionClass('implementsClass');
    
    $interfaces = $reflectionClass->getInterfaces();
    
    
    
    $implementsInterfaces = array();
    
    foreach ($interfaces as $interface) {
    
        if ($interface->getName() !== $reflectionClass->getName()) {
    
            $implementsInterfaces[] = $interface;
    
        }
    
    }
    
    


    위 코드에서, implements된 클래스의 인터페이스만을 `$implementsInterfaces` 변수에 저장합니다.

    또는, PHP 8.0 이상부터는 `ReflectionClass::getImplementedInterfaces()` 메서드를 사용할 수 있습니다.

    #hostingforum.kr
    php
    
    $reflectionClass = new ReflectionClass('implementsClass');
    
    $implementsInterfaces = $reflectionClass->getImplementedInterfaces();
    
    

    2025-06-04 05:02

  • 개발자 Q&A 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 25,704건 / 1 페이지

검색

게시물 검색