
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