8000 [Process] filter env vars for "argc" & "argv" specifically · symfony/symfony@11ccbcd · GitHub
[go: up one dir, main page]

Skip to content

Commit 11ccbcd

Browse files
[Process] filter env vars for "argc" & "argv" specifically
1 parent c552709 commit 11ccbcd

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public function start(callable $callback = null, array $env = [])
340340

341341
$envPairs = [];
342342
foreach ($env as $k => $v) {
343-
if (false !== $v) {
343+
if (false !== $v && 'argc' !== $k && 'argv' !== $k) {
344344
$envPairs[] = $k.'='.$v;
345345
}
346346
}
@@ -1171,25 +1171,12 @@ public function getEnv()
11711171
/**
11721172
* Sets the environment variables.
11731173
*
1174-
* Each environment variable value should be a string.
1175-
* If it is an array, the variable is ignored.
1176-
* If it is false or null, it will be removed when
1177-
* env vars are otherwise inherited.
1178-
*
1179-
* That happens in PHP when 'argv' is registered into
1180-
* the $_ENV array for instance.
1181-
*
1182-
* @param array $env The new environment variables
1174+
* @param array<string|\Stringable> $env The new environment variables
11831175
*
11841176
* @return $this
11851177
*/
11861178
public function setEnv(array $env)
11871179
{
1188-
// Process can not handle env values that are arrays
1189-
$env = array_filter($env, function ($value) {
1190-
return !\is_array($value);
1191-
});
1192-
11931180
$this->env = $env;
11941181

11951182
return $this;
@@ -1673,14 +1660,7 @@ private function getDefaultEnv(): array
16731660
{
16741661
$env = getenv();
16751662
$env = array_intersect_key($env, $_SERVER) ?: $env;
1676-
unset($env['argc'], $env['argv']);
1677-
1678-
foreach ($_ENV as $k => $v) {
1679-
if (\is_string($v)) {
1680-
$env[$k] = $v;
1681-
}
1682-
}
16831663

1684-
return $env;
1664+
return $_ENV + $env;
16851665
}
16861666
}

0 commit comments

Comments
 (0)
0