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 when running on case-insensitive file systems (like Windows). On Linux hosts it still works as case-sensitive. 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
to improve cross-platform behavior, unless you are certain about the casing of the environment variable you are trying to retrieve.
Steve Clay's comment in this answer highlights another difference:
Added getenv()
advantage: you don't need to check isset
/empty
before access. getenv()
won't emit notices.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…