Get value of dynamically chosen class constant in PHP

前端 未结 8 1165
无人共我
无人共我 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:22

    Use Reflection

    $r = new ReflectionClass('ThingIDs');
    $id = $r->getConstant($thing);
    

提交回复
热议问题