tau tau - 1 year ago 94
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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download