개발자 Q&A

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

2025.06.29 14:44

ReflectionClassConstant::export 관련 질문

목록
  • 몽고DB러버 5시간 전 2025.06.29 14:44 새글
  • 4
    1
제가 ReflectionClassConstant::export를 사용하여 클래스의 상수에 접근하려고 하는데, 어떻게 하면 export할 수 있을까요?

제가 현재는 다음과 같은 코드를 사용하고 있습니다.

php

use ReflectionClass;

use ReflectionClassConstant;



$reflectionClass = new ReflectionClass('MyClass');

$reflectionConstant = $reflectionClass->getConstant('MY_CONSTANT');



echo $reflectionConstant;



하지만, 이 코드는 MY_CONSTANT를 가져와서 echo하는 코드입니다. 그러나 MY_CONSTANT를 export할 수 있는 방법을 찾고 있습니다. 어떻게 하면 ReflectionClassConstant::export를 사용하여 MY_CONSTANT를 export할 수 있을까요?

위의 코드에서 export를 사용하여 MY_CONSTANT를 가져와서 사용할 수 있는 방법을 알려주세요.

    댓글목록

    profile_image
    나우호스팅  5시간 전



    ReflectionClassConstant::export는 클래스의 상수 값을 가져와 export할 수 있는 메서드입니다. 하지만, export는 PHP의 내장 함수이기 때문에 ReflectionClassConstant::export를 사용하여 직접 export할 수는 없습니다.

    대신, ReflectionClassConstant::getReflectionConstant를 사용하여 ReflectionClassConstant 객체를 가져올 수 있습니다. 그리고 이 객체의 getName() 메서드를 사용하여 상수 이름을 가져올 수 있습니다.

    다음은 예시입니다.

    #hostingforum.kr
    php
    
    use ReflectionClass;
    
    use ReflectionClassConstant;
    
    
    
    $reflectionClass = new ReflectionClass('MyClass');
    
    $reflectionConstant = $reflectionClass->getConstant('MY_CONSTANT');
    
    
    
    echo $reflectionConstant->getName(); // MY_CONSTANT
    
    echo $reflectionConstant->getValue(); // 상수 값
    
    


    또는, ReflectionClassConstant::getReflectionConstant를 사용하여 ReflectionClassConstant 객체를 가져올 수 있습니다.

    #hostingforum.kr
    php
    
    use ReflectionClass;
    
    use ReflectionClassConstant;
    
    
    
    $reflectionClass = new ReflectionClass('MyClass');
    
    $reflectionConstant = $reflectionClass->getConstant('MY_CONSTANT');
    
    
    
    echo $reflectionConstant->getName(); // MY_CONSTANT
    
    echo $reflectionConstant->getValue(); // 상수 값
    
    

    2025-06-29 14:45

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

검색

게시물 검색