Skip to content

Instantly share code, notes, and snippets.

@cs278
Created November 7, 2013 14:13
Show Gist options
  • Save cs278/7355160 to your computer and use it in GitHub Desktop.
Save cs278/7355160 to your computer and use it in GitHub Desktop.
Fetch environment even if the $_ENV superglobal is unset due to the `variables_order` INI setting.
<?php
function getEnvironment() {
if ($_ENV) {
return $_ENV;
}
$keys = array_keys($_SERVER);
return $_ENV = array_filter(
array_combine(
$keys,
array_map('getenv', $keys)
),
'is_string'
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment