Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 81c9e39

Browse files
bug #45931 [Process] Fix Process::getEnv() when setEnv() hasn't been called before (asika32764)
This PR was merged into the 4.4 branch. Discussion ---------- [Process] Fix Process::getEnv() when setEnv() hasn't been called before | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT ----- AS `getEnv()` return type is array, if a `Process` object has no default env and is NULL value, calling `getEnv()` will get error. ``` php $process = $someObject->createProcess(); // Get process from some object, but we don't know the environment // We want to check the env $env = $process->getEnv(); // Error: return type must be array, NULL given. ``` Commits ------- a5bf740 [Process] Fix Process::getEnv() when setEnv() hasn't been called before
2 parents 464385f + a5bf740 commit 81c9e39

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Process implements \IteratorAggregate
5353
private $hasCallback = false;
5454
private $commandline;
5555
private $cwd;
56-
private $env;
56+
private $env = [];
5757
private $input;
5858
private $starttime;
5959
private $lastOutputTime;

src/Symfony/Component/Process/Tests/ProcessTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,8 +1505,11 @@ public function testPreparedCommandWithNoValues()
15051505

15061506
public function testEnvArgument()
15071507
{
1508-
$env = ['FOO' => 'Foo', 'BAR' => 'Bar'];
15091508
$cmd = '\\' === \DIRECTORY_SEPARATOR ? 'echo !FOO! !BAR! !BAZ!' : 'echo $FOO $BAR $BAZ';
1509+
$p = Process::fromShellCommandline($cmd);
1510+
$this->assertSame([], $p->getEnv());
1511+
1512+
$env = ['FOO' => 'Foo', 'BAR' => 'Bar'];
15101513
$p = Process::fromShellCommandline($cmd, null, $env);
15111514
$p->run(null, ['BAR' => 'baR', 'BAZ' => 'baZ']);
15121515

0 commit comments

Comments
 (0)