개발자 Q&A

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

2025.03.25 13:58

ReflectionClass::hasMethod 관련 질문

목록
  • Swift매니아 1일 전 2025.03.25 13:58
  • 4
    1
저는 ReflectionClass::hasMethod를 사용하여 클래스의 메소드를 확인하려고 합니다. 하지만, 이 메소드는 클래스의 메소드가 존재하는지 여부를 반환하는 것뿐만 아니라, 상속받은 메소드도 포함되는 것인지 궁금합니다.

해당 메소드는 상속받은 메소드를 포함하여 클래스의 모든 메소드를 확인하나요? 아니면, 클래스의 직접 정의된 메소드만 확인하나요?

    댓글목록

    profile_image
    나우호스팅  1일 전



    ReflectionClass::hasMethod 메소드는 클래스의 직접 정의된 메소드만 확인합니다. 상속받은 메소드는 포함되지 않습니다.

    예를 들어, 다음 코드를 살펴보겠습니다.

    #hostingforum.kr
    php
    
    class ParentClass {
    
        public function parentMethod() {}
    
    }
    
    
    
    class ChildClass extends ParentClass {
    
        public function childMethod() {}
    
    }
    
    
    
    $reflection = new ReflectionClass('ChildClass');
    
    echo $reflection->hasMethod('parentMethod') ? 'true' : 'false'; // false
    
    echo $reflection->hasMethod('childMethod') ? 'true' : 'false'; // true
    
    


    위 코드에서, ReflectionClass::hasMethod 메소드는 ChildClass의 직접 정의된 메소드인 childMethod를 확인하지만, 상속받은 메소드인 parentMethod는 확인하지 않습니다.

    2025-03-25 13:59

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

검색

게시물 검색