From c6969756e8a0a54461e5513a3c60a27e7e5f0d27 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 28 Feb 2020 16:27:06 +0100 Subject: [PATCH] Make sure $_SERVER is updated when putenv updates environment variables, fixes #8298 --- src/Composer/Console/Application.php | 3 ++- src/Composer/EventDispatcher/EventDispatcher.php | 3 ++- src/Composer/Installer.php | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 74e270a96..cc39c587b 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -131,7 +131,8 @@ class Application extends BaseApplication if ($input->hasParameterOption('--no-cache')) { $io->writeError('Disabling cache usage', true, IOInterface::DEBUG); - putenv('COMPOSER_CACHE_DIR='.(Platform::isWindows() ? 'nul' : '/dev/null')); + $_SERVER['COMPOSER_CACHE_DIR'] = Platform::isWindows() ? 'nul' : '/dev/null'; + putenv('COMPOSER_CACHE_DIR='.$_SERVER['COMPOSER_CACHE_DIR']); } // switch working dir diff --git a/src/Composer/EventDispatcher/EventDispatcher.php b/src/Composer/EventDispatcher/EventDispatcher.php index 45288825d..a5797fdae 100644 --- a/src/Composer/EventDispatcher/EventDispatcher.php +++ b/src/Composer/EventDispatcher/EventDispatcher.php @@ -242,7 +242,8 @@ class EventDispatcher $finder = new PhpExecutableFinder(); $phpPath = $finder->find(false); if ($phpPath) { - putenv('PHP_BINARY=' . $phpPath); + $_SERVER['PHP_BINARY'] = $phpPath; + putenv('PHP_BINARY=' . $_SERVER['PHP_BINARY']); } } diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index ff40b618f..2269d7958 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -200,8 +200,8 @@ class Installer } if ($this->runScripts) { - $devMode = (int) $this->devMode; - putenv("COMPOSER_DEV_MODE=$devMode"); + $_SERVER['COMPOSER_DEV_MODE'] = (int) $this->devMode; + putenv('COMPOSER_DEV_MODE='.$_SERVER['COMPOSER_DEV_MODE']); // dispatch pre event $eventName = $this->update ? ScriptEvents::PRE_UPDATE_CMD : ScriptEvents::PRE_INSTALL_CMD;