Can I access a PHP Class Constant using a variable for the constant name?

前端 未结 1 1272
无人及你
无人及你 2021-02-19 14:09

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 c

相关标签:
1条回答
  • 2021-02-19 14:59
    $variable = $classname.'::'.$constant;
    
    constant($variable);
    

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

    0 讨论(0)
提交回复
热议问题