tau tau - 17 days ago 10
PHP Question

getenv() vs. $_ENV in PHP

What is the difference between

getenv()
and
$_ENV
?

Any trade-offs between using either?

I noticed sometimes
getenv()
gives me what I need, while
$_ENV
does not (such as
HOME
).

Answer

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.

Comments