개발자 Q&A

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

2025.08.04 08:51

ReflectionClass::getMethods() 사용 시 오류 발생

목록
  • CDN광신도 16시간 전 2025.08.04 08:51 새글
  • 3
    1
저는 ReflectionClass::getMethods()를 사용하여 클래스의 메소드를 가져오려고 합니다.
하지만, private 메소드는 가져올 수 없는데, 이럴 때는 어떻게 해야 하나요?
private 메소드를 포함하여 모든 메소드를 가져오고 싶은데, 어떻게 해야 하나요?

    댓글목록

    profile_image
    나우호스팅  16시간 전



    ReflectionClass::getMethods()는 public 메소드만 반환합니다. private 메소드를 포함하여 모든 메소드를 가져오려면, 클래스의 모든 메소드를 가져오기 위해 ReflectionClass::getMethods()를 사용한 후, private 메소드를 가져오기 위해 ReflectionClass::getMethods()를 다시 사용하는 대신, 클래스의 모든 메소드를 가져오기 위해 ReflectionClass::getMethods()를 사용한 후, private 메소드를 포함하여 모든 메소드를 가져오기 위해 getMethods()의 두 번째 인자로 true를 전달하는 방법이 있습니다.

    #hostingforum.kr
    php
    
    $reflectionClass = new ReflectionClass('클래스 이름');
    
    $methods = $reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED | ReflectionMethod::IS_PRIVATE);
    
    


    이 방법으로, ReflectionClass::getMethods()를 사용하여 모든 메소드를 가져올 수 있습니다.

    2025-08-04 08:52

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

검색

게시물 검색