개발자 Q&A

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

2025.07.18 06:00

ReflectionFunctionAbstract::getStaticVariables 관련 질문

목록
  • DevOps성애자 1일 전 2025.07.18 06:00
  • 9
    1
제가 공부하려고 하는 PHP Reflection 클래스의 getStaticVariables 메서드를 이해하지 못해 도움을 요청합니다.

getStaticVariables 메서드는 Reflection 클래스의 메서드 중 하나로, 클래스의 정적 변수를 반환합니다. 그러나 이 메서드를 사용하는 방법에 대한 이해가 부족합니다.

getStaticVariables 메서드를 사용하여 클래스의 정적 변수를 가져올 때, 해당 변수가 클래스 내부에서 선언된 변수인지, 또는 상수 변수인지 구분하는 방법을 알려주시면 감사하겠습니다.

    댓글목록

    profile_image
    나우호스팅  1일 전



    getStaticVariables 메서드는 클래스의 정적 변수를 반환합니다. 이 메서드를 사용하여 클래스의 정적 변수를 가져올 때, 해당 변수가 클래스 내부에서 선언된 변수인지, 또는 상수 변수인지 구분하는 방법은 다음과 같습니다.

    1. 클래스 내부에서 선언된 정적 변수는 `ReflectionClass::getStaticVariables()` 메서드를 사용하여 반환됩니다.
    2. 상수 변수는 `ReflectionClass::getStaticProperties()` 메서드를 사용하여 반환됩니다.

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

    #hostingforum.kr
    php
    
    class MyClass {
    
        public static $myVariable = '변수';
    
        public static $myConstant = '상수';
    
    }
    
    
    
    $reflectionClass = new ReflectionClass('MyClass');
    
    $staticVariables = $reflectionClass->getStaticVariables();
    
    $staticProperties = $reflectionClass->getStaticProperties();
    
    
    
    print_r($staticVariables); // Array ( [myVariable] => 변수 )
    
    print_r($staticProperties); // Array ( [myConstant] => 상수 )
    
    


    위 코드에서, `getStaticVariables()` 메서드는 클래스 내부에서 선언된 정적 변수인 `$myVariable`를 반환하고, `getStaticProperties()` 메서드는 상수 변수인 `$myConstant`를 반환합니다.

    2025-07-18 06:01

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

검색

게시물 검색