Skip to content

Commit

Permalink
Fix inconsistency with .env loaders out of the box
Browse files Browse the repository at this point in the history
PHP .env loaders such as `symfony/dotenv` or `vlucas/phpdotenv` populate `$_SERVER` and `$_ENV` out of the box, but don't call `putenv()` in order to preserve thread safeness. This means .env is loaded by them, but AWS SDK does not read it, creating inconsistent experience when handling real env variables and env variables loaded by these loaders
  • Loading branch information
ostrolucky committed Dec 24, 2023
1 parent e2d3ff9 commit 27567de
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,6 @@ function getenv(string $name)
{
$out = \getenv($name);

return $out === false ? ($_SERVER[$name] ?? false) : $out;
return $out === false ? ($_ENV[$name] ?? false) : $out;
}

2 changes: 1 addition & 1 deletion tests/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,6 @@ public function getIniFileServiceTestCases()
public function testgetenv()
{
$this->assertEquals(false, Aws\getenv('FOO'));
$this->assertEquals($_SERVER['FOO'] = 'bar', Aws\getenv('FOO'));
$this->assertEquals($_ENV['FOO'] = 'bar', Aws\getenv('FOO'));
}
}

0 comments on commit 27567de

Please sign in to comment.