Get value of dynamically chosen class constant in PHP

前端 未结 8 1199
无人共我
无人共我 2020-11-29 03:38

I would like to be able to do something like this:

class ThingIDs
{
    const Something = 1;
    const AnotherThing = 2;
}

$thing = \'Something\';
$id = Thi         


        
8条回答
  •  盖世英雄少女心
    2020-11-29 04:27

    If you are using namespaces, you should include the namespace with the class.

    echo constant('My\Application\ThingClass::ThingConstant'); 
    

提交回复
热议问题