개발자 Q&A

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

2025.05.18 10:24

ReflectionClass::getInterfaceNames에 대한 질문

목록
  • Android개발광 1일 전 2025.05.18 10:24
  • 5
    1
안녕하세요 선생님, ReflectionClass::getInterfaceNames 에서 interface 이름을 얻는 방법을 알려주세요.

예를 들어, interface A implements B, C 인터페이스를 구현할 경우, getInterfaceNames()를 호출하면 어떤 결과가 나올까요?

interface A implements B, C 인 경우 getInterfaceNames()의 결과는 어떤 값이 나올까요?

그리고 interface A implements B, C, D 인 경우 getInterfaceNames()의 결과는 어떤 값이 나올까요?

선생님의 도움이 필요합니다.

    댓글목록

    profile_image
    나우호스팅  1일 전



    ReflectionClass::getInterfaceNames() 메소드는 클래스가 구현하는 인터페이스의 이름을 반환합니다.

    interface A implements B, C 인 경우 getInterfaceNames()의 결과는 array('B', 'C') 가 반환됩니다.

    interface A implements B, C, D 인 경우 getInterfaceNames()의 결과는 array('B', 'C', 'D') 가 반환됩니다.

    이 메소드는 클래스의 인터페이스 이름을 반환하기 때문에, 인터페이스 이름이 여러 개인 경우 모든 인터페이스의 이름이 반환됩니다.

    이 메소드는 ReflectionClass의 인스턴스에 대해 호출되어야 하며, 클래스가 인터페이스를 구현하지 않은 경우 빈 배열이 반환됩니다.

    예를 들어, 다음과 같은 코드를 작성할 수 있습니다.

    #hostingforum.kr
    php
    
    interface B {}
    
    interface C {}
    
    interface D {}
    
    
    
    class A implements B, C {}
    
    class B implements D {}
    
    
    
    $reflectionClass = new ReflectionClass('A');
    
    print_r($reflectionClass->getInterfaceNames()); // array('B', 'C')
    
    
    
    $reflectionClass = new ReflectionClass('B');
    
    print_r($reflectionClass->getInterfaceNames()); // array('D')
    
    

    2025-05-18 10:25

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

검색

게시물 검색