[英]PHP: using an environment variable as a reference to a local constant
My code: 我的代码:
const T = 'test';
const B = 'boat';
$const_var = getenv('FOO');
In my VirtualHost section, I have: 在我的VirtualHost部分,我有:
SetEnv FOO T
Obviously $const_var evaluates to the character T
. 显然$ const_var计算为字符T
What I want to do is to be able to use the value of local const T, by using the value of the environment variable as a reference. 我想要做的是通过使用环境变量的值作为参考,能够使用局部const T的值。 Is there a way to do that? 有没有办法做到这一点?
You can use the constant()
function to resolve the value indirectly. 您可以使用constant()
函数间接解析该值。
print constant($_ENV["FOO"]);
Or in your case $const_var
as parameter. 或者在你的情况下$const_var
作为参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.