Getting static property from a class with dynamic class name in PHP

后端 未结 11 522
情歌与酒
情歌与酒 2020-11-30 01:44

I have this:

  • one string variable which holds the class name ($classname)
  • one string variable with holds the property name ($propert
11条回答
  •  孤街浪徒
    2020-11-30 02:04

    Even if for you said eval is out of the question, prior PHP 5.3 the easiest solution is still by using eval:

    eval("\$propertyval = $classname::\$propertyname;");
    echo $propertyval;
    

提交回复
热议问题