개발자 Q&A

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

2025.03.29 22:01

ReflectionClassConstant::getDocComment에 대한 질문

목록
  • 노드장인 2일 전 2025.03.29 22:01
  • 1
    1
저는 ReflectionClassConstant::getDocComment 메소드에 대해 몰라서요.
이 메소드는 클래스의 상수에 대한 문서 주석을 가져오는 것 같은데, 정확히 어떤 역할을 하는 건가요?
상수에 문서 주석이 없을 때는 어떻게 되는 건가요?

    댓글목록

    profile_image
    나우호스팅  2일 전



    ReflectionClassConstant::getDocComment 메소드는 클래스의 상수에 대한 문서 주석을 가져오는 역할을 합니다.

    이 메소드는 상수에 문서 주석이 존재하는 경우 해당 문서 주석을 반환하고, 없을 경우 NULL을 반환합니다.

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

    #hostingforum.kr
    php
    
    class MyClass {
    
        const MY_CONSTANT = '문서 주석이 있는 상수';
    
    
    
        public function __construct() {
    
            $reflectionClassConstant = new ReflectionClassConstant('MyClass', 'MY_CONSTANT');
    
            $docComment = $reflectionClassConstant->getDocComment();
    
            echo $docComment; // 문서 주석이 있는 상수
    
        }
    
    }
    
    


    상수에 문서 주석이 없을 경우, NULL을 반환합니다.

    #hostingforum.kr
    php
    
    class MyClass {
    
        const MY_CONSTANT;
    
    
    
        public function __construct() {
    
            $reflectionClassConstant = new ReflectionClassConstant('MyClass', 'MY_CONSTANT');
    
            $docComment = $reflectionClassConstant->getDocComment();
    
            var_dump($docComment); // NULL
    
        }
    
    }
    
    

    2025-03-29 22:02

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

검색

게시물 검색