【发布时间】:2011-04-29 01:18:33
【问题描述】:
我正在尝试动态创建一个常量名称,然后获取该值。
define( CONSTANT_1 , "Some value" ) ;
// try to use it dynamically ...
$constant_number = 1 ;
$constant_name = ("CONSTANT_" . $constant_number) ;
// try to assign the constant value to a variable...
$constant_value = $constant_name;
但我发现 $constant 值仍然包含常量的名称,而不是值。
我也尝试了第二级间接$$constant_name 但这会使它成为变量而不是常量。
有人可以解释一下吗?
【问题讨论】:
标签: php constants indirection