Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对动态常量名称声明有一点问题。我不知道为什么定义 $constName 的表达式没有被正确评估:
这是我的代码:
$type2 = "type2"; $env = "env"; $constName = "test_$type2_$env"; return constant(__CLASS__."::$constName");
之后,我没有得到正确的值:test_type2_env,而是这个:test_env
提前致谢。
尝试
$constName = "test_{$type2}_$env";
因为 PHP 知道您需要 'type2_' 变量的值。