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).
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
According to the php documentation about getenv, they are exactly the same, except that
getenvwill 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:Because of that, I would probably opt to use
getenvto 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: