diff --git a/src/Core/Environment.php b/src/Core/Environment.php index 6d5f1f34b..c8f6cb806 100644 --- a/src/Core/Environment.php +++ b/src/Core/Environment.php @@ -43,7 +43,12 @@ class Environment public static function getVariables() { // Suppress return by-ref - return array_merge($GLOBALS, [ 'env' => static::$env ]); + $vars = [ 'env' => static::$env ]; + foreach ($GLOBALS as $varName => $varValue) { + $vars[$varName] = $varValue; + } + + return $vars; } /** diff --git a/tests/php/Core/EnvironmentTest.php b/tests/php/Core/EnvironmentTest.php index 220f47b58..ccd31e83e 100644 --- a/tests/php/Core/EnvironmentTest.php +++ b/tests/php/Core/EnvironmentTest.php @@ -53,4 +53,17 @@ class EnvironmentTest extends SapphireTest Environment::setVariables($vars); $this->assertEquals('initial', Environment::getEnv('_ENVTEST_RESTORED')); } + + public function testGetVariables() + { + $GLOBALS['test'] = 'global'; + $vars = Environment::getVariables(); + $this->assertArrayHasKey('test', $vars); + $this->assertEquals('global', $vars['test']); + $this->assertEquals('global', $GLOBALS['test']); + + $vars['test'] = 'fail'; + $this->assertEquals('fail', $vars['test']); + $this->assertEquals('global', $GLOBALS['test']); + } }