Skip to content

Instantly share code, notes, and snippets.

@uzulla
Last active September 10, 2019 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uzulla/464e036bcbe2c0de0ecadbf7175ca478 to your computer and use it in GitHub Desktop.
Save uzulla/464e036bcbe2c0de0ecadbf7175ca478 to your computer and use it in GitHub Desktop.
getenv() will not work with `vlucas/phpdotenv` when set "disable_functions=putenv" at php.ini

getenv() will not work with vlucas/phpdotenv when set "disable_functions=putenv" at php.ini

php.ini

disable_functions=putenv

you could be check by phpinfo()

in code

some.env

SOMETHING=OK

code.php

Dotenv::create("some.env")->load();

var_dump(getenv("SOMETHING")); => false
var_dump($_ENV["SOMETHING"]); => "OK"

Got NO runtime errors. because getenv is not disabled actually.

why ?

vlucas/phpdotenv will be check available method/function.

But, Didn't check getenv (that is right design, I thought).

woooo....

solution idea(?)

function _getenv($name){
  if(getenv($name) !== false) return getenv($name); 
  else if(isset($_ENV[$name])) return $_ENV[$name];
  else return false;
}

# or, replace getenv to $_ENV

umm....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment