简体   繁体   中英

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:

SetEnv FOO T

Obviously $const_var evaluates to the character 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. Is there a way to do that?

You can use the constant() function to resolve the value indirectly.

 print constant($_ENV["FOO"]);

Or in your case $const_var as parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM