AKA Marketing.com Logo            VISIT THE BLOG            

Blogged thoughts, is our web blog. Expect views, opinion, rants and tirades about everything and anything 

« Home / Forums »        


Subscribe to our SEO / IT related blog by entering your email address below

Blogged thoughts

| by the www.akamarketing.com team

$_ENV, the Environment variable array is empty in PHP

The environment variables are usually made available to your scripts via $_ENV, just like $_POST, $_GET etc. are. It seems however that the registration by PHP of these kind of variables for use in your scripts is governed by a configuration option called variables_order in the php.ini file. By default many of the latest installs (and associated php.ini’s) of PHP will have this option set to ‘GPCS’, which stands for Get, Post, Cookie and Built-in variables respectively.

Therefore if you find your php_info() function call returning a bucket load of environment related information but yet a print_r($_ENV) returns an empty array () check the aforementioned setting and be sure to add E in there somewhere so as to instruct PHP to make environment variables available to you and your scripts.

While I’m not 100% certain I believe the ordering of the letters is only important when you have the register_globals option set to on. If register_globals is set to on (off by default since 4.2 and ditched in 6.0) then PHP will make all the variable kinds (Post, Get etc.) specified in variables_order available as global variables in the order you specified in that directive. Imagine for instance that you have ‘EGP’ specified in variables_order and register_globals set to on, if you have a variable called ‘Path’ in both the $_ENV and $_POST arrays, the value from the post array will overwrite the value from the environment array and thus the global variable $Path will hold information from $_POST and not $_ENV. If register_globals was turned to off, you would simply access all array indexes by their full name such as $_ENV["Path"] and $_POST["Path"] and thus they will be considered as 100% different variables.

3 Comments on “$_ENV, the Environment variable array is empty in PHP”
1| David Callan said,

Just noticed that I had all references to the environment array down as $_EVN and not $_ENV. I’ve always suspected I was slightly dyslexic as I mix letters up like that a bit. Hey but I’m #1 on Google for ‘$_EVN’…

2| Xeross said,

Thanks, was wondering why they were empty.

3| Juergen said,

Hello, guys,
thank you so so much for this hint.
After reinstalling my developer environment (Xampp) I wasn’t able to see those ENV variables anymore, although PHP_INFO() still showed them.
This solved it.
Thanks again

Leave a Comment
12 Lorcan Crescent, Santry, Dublin 9, Ireland +353 87 9807629