개발자 Q&A

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

2025.08.02 16:28

ReflectionMethod::isProtected에 대한 이해를 부탁드립니다.

목록
  • 클린코더 6시간 전 2025.08.02 16:28 새글
  • 3
    1
제가 ReflectionMethod 클래스를 공부하고 있는데, isProtected 메서드에 대한 이해가 조금씩 막히고 있습니다.

isProtected 메서드는 ReflectionMethod 클래스의 메서드 중 하나로, 해당 메서드가 protected 키워드를 사용한 것인지 확인하는 역할을 합니다.

하지만 protected 키워드가 메서드의 접근 레벨을 지정하는 데 사용되는데, 이 메서드가 어떤 기준으로 protected 키워드의 사용 여부를 판단하는지 이해가 잘 안됩니다.

protected 키워드를 사용한 메서드와 그렇지 않은 메서드의 차이점을 설명해주시거나, 이 메서드가 어떻게 동작하는지 알려주시면 감사하겠습니다.

    댓글목록

    profile_image
    나우호스팅  6시간 전



    ReflectionMethod 클래스의 isProtected 메서드는 protected 키워드가 사용된 메서드인지 아닌지를 확인하는 데 사용됩니다.

    protected 키워드는 메서드의 접근 레벨을 지정하는 데 사용되며, 해당 클래스의 자식 클래스에서 접근할 수 있도록 허용합니다.

    isProtected 메서드는 메서드의 이름을 통해 protected 키워드가 사용된 경우 true를 반환하고, 그렇지 않은 경우 false를 반환합니다.

    이 메서드는 PHPDoc의 @protected 태그나 PHP의 protected 키워드가 사용된 메서드의 이름을 통해 protected 키워드가 사용된 경우를 확인합니다.

    예를 들어, 다음 코드는 protected 키워드가 사용된 메서드인 경우 true를 반환합니다.

    #hostingforum.kr
    php
    
    class ParentClass {
    
        protected function protectedMethod() {}
    
    }
    
    
    
    class ChildClass extends ParentClass {
    
        public function test() {
    
            $reflectionMethod = new ReflectionMethod('ChildClass', 'test');
    
            $isProtected = $reflectionMethod->isProtected();
    
            var_dump($isProtected); // bool(true)
    
        }
    
    }
    
    


    반면에, 다음 코드는 protected 키워드가 사용되지 않은 메서드인 경우 false를 반환합니다.

    #hostingforum.kr
    php
    
    class ParentClass {
    
        public function publicMethod() {}
    
    }
    
    
    
    class ChildClass extends ParentClass {
    
        public function test() {
    
            $reflectionMethod = new ReflectionMethod('ChildClass', 'test');
    
            $isProtected = $reflectionMethod->isProtected();
    
            var_dump($isProtected); // bool(false)
    
        }
    
    }
    
    

    2025-08-02 16:29

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

검색

게시물 검색