Skip to content

Commit

Permalink
Use getenv() function instead of $_ENV global variable. (#1887)
Browse files Browse the repository at this point in the history
* ComposerTask: update code & doc #1163

* refactor(PropertyTask): Use getenv() function instead of $_ENV global variable.

The PropertyTask's "environment" attribute fails to work as expected in some systems, sometimes $_ENV is an empty array.
This behavior is system-dependent and determined by the "variables_order" directive in php.ini.

To fix this I replaced $_ENV by getenv() function, as this ensures a consistent behaviour.

* https://www.php.net/manual/en/ini.core.php#ini.variables-order
* https://stackoverflow.com/questions/8798294/getenv-vs-env-in-php
  • Loading branch information
jawira authored Dec 16, 2024
1 parent 5fd4656 commit b00dfb5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Phing/Task/System/PropertyTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ protected function loadEnvironment(string $prefix)
$prefix .= '.';
}
$this->log("Loading Environment {$prefix}", Project::MSG_VERBOSE);
foreach ($_ENV as $key => $value) {
foreach (getenv() as $key => $value) {
$props->setProperty($prefix . '.' . $key, $value);
}
$this->addProperties($props);
Expand Down
5 changes: 3 additions & 2 deletions tests/Phing/Test/Task/System/PropertyTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ public function setUp(): void

public function test1(): void
{
// should get no output at all
$this->expectOutputAndError('test1', '', '');
putenv('MESSAGE=foo bar baz');
$this->executeTarget(__FUNCTION__);
$this->assertPropertyEquals('testenv.MESSAGE', 'foo bar baz');
}

public function test2(): void
Expand Down

0 comments on commit b00dfb5

Please sign in to comment.