我正在使用一个定义了近 20 个常量的类,因为我希望所有这些常量值都在一个数组中,我只想知道
有没有什么方法可以创建一个类的所有常量的数组?
我尝试过compact https://www.php.net/manual/en/function.compact.php但它不适用于常量。
class Alpha
{
const ONE = 'fixone';
const TWO = 'fix_two';
const THREE = 3
public function __construct()
{
protected $arr_constant = compact(ONE,TWO,THREE); // gives FATAL Error
// is there any method which collect all consant and create an array?
protected $arr_contact = get_all_constant(__CLASS__);
var_dump($arr_constant);
}
}
$ref = new ReflectionClass('Alpha');
var_dump($ref->getConstants());
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)