Skip to content

[Process] defaultEnv not properly generated in PHP build-in webserver #44066

Closed
@lukas-staab

Description

@lukas-staab

Symfony version(s) affected

process 5.3.7

Description

The php-doc says

* @param array|null $env The environment variables or null to use the same environment as the current PHP process

With $env = null it will take the Enviroment of the current process. This is not allways true.
Using the PHP Build-In Webserver (php -S localhost:80) $_ENV is empty (but getenv() is not), so
foreach ($_ENV as $k => $v) {

gives unexpected result. Especially the PATH variable remains unset, which leads to unfound binaries

How to reproduce

Use php build in webserver (see above) and use e.g

$p = new Process(['pdflatex'], __DIR__, null)

(set $env = null)
-> PATH Variable is not set in $_ENV only in getenv()

Possible Solution

Use getEnv() instead of $_ENV or check for

if (php_sapi_name() === 'cli-server') {

Additional Context

php -S is (often) used in local development environments. Missing PATH Variables can be a big issue there.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions