Reflection ReflectionClass::getConstant

(PHP 5, PHP 7, PHP 8)

ReflectionClass::getConstant — 정의된 상수 가져오기


설명

public ReflectionClass::getConstant(string $name): mixed

정의된 상수를 가져옵니다.


매개변수

name
가져올 클래스 상수의 이름입니다.

반환 값

이름 name이 있는 상수 값입니다. 클래스에서 상수를 찾을 수 없으면 false를 반환합니다.


Examples

예제 #1 ReflectionClass::getConstant() 사용

                  
<?php

class Example {
    const C1 = false;
    const C2 = 'I am a constant';
}

$reflection = new ReflectionClass('Example');

var_dump($reflection->getConstant('C1'));
var_dump($reflection->getConstant('C2'));
var_dump($reflection->getConstant('C3'));
?>
                  
                

위의 예는 다음을 출력합니다.

bool(false)
string(15) "I am a constant"
bool(false)
                

기타