tau tau - 6 months ago 49
PHP Question

getenv() vs. $_ENV in PHP

What is the difference between


Any trade-offs between using either?

I noticed sometimes
gives me what I need, while
does not (such as


According to the php documentation about getenv, they are exactly the same, except that getenv will look for the variable in a case-insensitive manner. Most of the time it probably doesn't matter, but one of the comments on the documentation explains:

For example on Windows $_SERVER['Path'] is like you see, with the first letter capitalized, not 'PATH' as you might expect.

Because of that, I would probably opt to use getenv unless you are certain about the casing of the title of the variable you are trying to retrieve.