Skip to content

Commit

Permalink
fix issue where $_ENV contains array vals
Browse files Browse the repository at this point in the history
There are cases where $env or $_ENV can contain a value that is an array
This will cause Process to throw an Array to String conversion exception
Initially I submitted a patch of Process.php, however Fabien indicated
that it shouldn't be fixed there (see below pull request).

Before recently, a simple work around would be in php.ini to set:

  register_argc_argv = On

However with recent changes, this seems to no longer work.

Original pull request: #7354

See ticket #7196
  • Loading branch information
mmucklo authored and fabpot committed Jun 13, 2013
1 parent c27735d commit 8764944
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Symfony/Component/Process/ProcessBuilder.php
Expand Up @@ -151,6 +151,9 @@ public function getProcess()
$env = $this->env;
}

// Process can not handle env values that are arrays
$env = $env ? array_filter($env, function ($value) { if (!is_array($value)) { return true; } }) : $env;

return new Process($script, $this->cwd, $env, $this->stdin, $this->timeout, $options);
}
}
16 changes: 16 additions & 0 deletions src/Symfony/Component/Process/Tests/ProcessBuilderTest.php
Expand Up @@ -45,6 +45,22 @@ public function testProcessShouldInheritAndOverrideEnvironmentVars()
$_ENV = $snapshot;
}

public function testProcessBuilderShouldNotPassEnvArrays()
{
$snapshot = $_ENV;
$_ENV = array('a' => array('b', 'c'), 'd' => 'e', 'f' => 'g');
$expected = array('d' => 'e', 'f' => 'g');

$pb = new ProcessBuilder();
$pb->add('a')->inheritEnvironmentVariables()
->setEnv('d', 'e');
$proc = $pb->getProcess();

$this->assertEquals($expected, $proc->getEnv(), '->inheritEnvironmentVariables() removes array values from $_ENV');

$_ENV = $snapshot;
}

public function testInheritEnvironmentVarsByDefault()
{
$pb = new ProcessBuilder();
Expand Down

0 comments on commit 8764944

Please sign in to comment.