Skip to content

[Process] intersect with getenv() to populate default envs #44070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -1671,13 +1671,8 @@ private function replacePlaceholders(string $commandline, array $env)

private function getDefaultEnv(): array
{
$env = [];

foreach ($_SERVER as $k => $v) {
if (\is_string($v) && false !== $v = getenv($k)) {
Copy link

@devsi devsi Nov 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removal of the is_string check seems to be allowing arrays to get in to the env array as values. This causes an error "ErrorException Array to string conversion" when the env vars are read as a string in the start() method()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already fixed, see #44208
Please create issue instead of commenting on closed PRs to report issue btw.

$env[$k] = $v;
}
}
$env = getenv();
$env = array_intersect_key($env, $_SERVER) ?: $env;
Comment on lines +1674 to +1675
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means if the current running process has added env vars putenv(), they still won't be detected though. One has to update $_SERVER + do putenv() for it to be taken into account.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, we are intentionally not compatible with putenv() here, because using putenv leads to blank pages in Windows


foreach ($_ENV as $k => $v) {
if (\is_string($v)) {
Expand Down