Description
Symfony version(s) affected
6.4.*
Description
When using Symfony\Component\Process\Process on Windows, if the environment variables array passed to proc_open contains any entry with an empty string as the key (e.g. '' => 'dev'), the underlying proc_open call fails silently without throwing an explicit error or exception (Message: Unable to launch a new process). This leads to process execution failures that are hard to diagnose.
How to reproduce
Create an environment array with an invalid entry having an empty string as key:
$env = [
'' => 'dev',
'APP_ENV' => 'dev',
];
Instantiate a Process and pass the environment array (or let the default environment include the invalid key).
Call $process->run() on Windows.
The process silently fails, returning no error or descriptive exception, making debugging difficult.
Expected behavior:
Process should validate environment variable keys before passing them to proc_open.
Environment variables with empty or invalid keys should be filtered out or trigger a clear exception.
Actual behavior:
proc_open fails silently when environment keys are empty strings or otherwise invalid on Windows.
No useful error is provided by Process, causing silent failure in process execution.
Possible Solution
In start
function ignore env variables with empty key. Example:
$envPairs = [];
foreach ($env as $k => $v) {
if (
false !== $v
&& is_string($k)
&& $k !== ''
&& false === \in_array($k, ['argc', 'argv', 'ARGC', 'ARGV'], true)) {
$envPairs[] = $k.'='.$v;
}
}
Additional Context
Symfony Process version: 6.4
PHP version: 8.3.14
OS: Windows 10