문제

When accessing a class constant I see that I can use a variable for the class name, e.g. $classname::CONST_VALUE.

What if I want to use a variable for the constant name, e.g. self::$constant. This does not seem to work. Is there a workaround?

도움이 되었습니까?

해결책

$variable = $classname.'::'.$constant;

constant($variable);

See the docs: http://php.net/constant

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top