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?
Define your constant in your top . php file, that will be included in all the other scripts. It may be your front controller, your config file, or a file created for this single purpose.
$_ENV is another superglobal associative array in PHP. It stores environment variables available to current script. $HTTP_ENV_VARS also contains the same information, but is not a superglobal, and now been deprecated. Environment variables are imported into global namespace.
You can use the constant()
function to resolve the value indirectly.
print constant($_ENV["FOO"]);
Or in your case $const_var
as parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With