Skip to content

Verbosity can be passed down to child processes - investigate effects on PIE subcommands #682

Description

@asgrim

reported by @theofidry here:

You can see it here:

    private function getDefaultEnv(): array
    {
        $env = getenv();
        $env = ('\\' === \DIRECTORY_SEPARATOR ? array_intersect_ukey($env, $_SERVER, 'strcasecmp') : array_intersect_key($env, $_SERVER)) ?: $env;

        return $_ENV + ('\\' === \DIRECTORY_SEPARATOR ? array_diff_ukey($env, $_ENV, 'strcasecmp') : $env);
    }

which is used in ::start() therefore ::run() and ::mustRun() too.

So if SHELL_VERBOSITY is set somehow, which can be explicitly by the user or using --quiet when using the Symfony Console (the Application sets the environment variable, see this piece of code).

Small reproducer:

<?php // demo.php

require __DIR__.'/vendor/autoload.php';

use Symfony\Component\Process\Process;

// Simulate SHELL_VERBOSITY having been set by the parent application.
putenv('SHELL_VERBOSITY=-1');
$_ENV['SHELL_VERBOSITY'] = '-1';
$_SERVER['SHELL_VERBOSITY'] = '-1';

$command = [
    PHP_BINARY,
    '-r',
    'echo getenv("SHELL_VERBOSITY"), PHP_EOL;',
];

// No environment explicitly provided: SHELL_VERBOSITY is inherited.
$inheritedProcess = new Process($command);
$inheritedProcess->mustRun();

echo 'Inherited: '.$inheritedProcess->getOutput();

// Explicitly reset the verbosity for the child process.
$overriddenProcess = new Process(
    command: $command,
    env: ['SHELL_VERBOSITY' => '0'],
);
$overriddenProcess->mustRun();

echo 'Overridden: '.$overriddenProcess->getOutput();

Then:

$ php demo.php
Inherited: -1
Overridden: 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions