diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 2c4d06f646..9078bb7d42 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -303,7 +303,7 @@ class Process implements \IteratorAggregate $envBackup = array(); if (null !== $env && $inheritEnv) { foreach ($env as $k => $v) { - $envBackup[$k] = getenv($v); + $envBackup[$k] = getenv($k); putenv(false === $v || null === $v ? $k : "$k=$v"); } $env = null; diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index 3066c6cc18..f95f95a25d 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -1397,6 +1397,20 @@ class ProcessTest extends TestCase $this->assertSame('', $process->getErrorOutput()); } + public function testEnvBackupDoesNotDeleteExistingVars() + { + putenv('existing_var=foo'); + $process = $this->getProcess('php -r "echo getenv(\'new_test_var\');"'); + $process->setEnv(array('existing_var' => 'bar', 'new_test_var' => 'foo')); + $process->inheritEnvironmentVariables(); + + $process->run(); + + $this->assertSame('foo', $process->getOutput()); + $this->assertSame('foo', getenv('existing_var')); + $this->assertFalse(getenv('new_test_var')); + } + public function testEnvIsInherited() { $process = $this->getProcessForCode('echo serialize($_SERVER);', null, array('BAR' => 'BAZ'));