From 008129be490abf310166f07c803816d86d4056a1 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 10 Dec 2024 16:37:56 +0100 Subject: [PATCH 1/2] Avoid duplicate errors in the output, fixes #12214 --- bin/composer | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bin/composer b/bin/composer index 8bc77e660..6b9db3aa4 100755 --- a/bin/composer +++ b/bin/composer @@ -42,7 +42,13 @@ if (!extension_loaded('iconv') && !extension_loaded('mbstring')) { } if (function_exists('ini_set')) { - @ini_set('display_errors', '1'); + // if display_errors is set to stderr or unset, we set it + if ('stderr' !== ini_get('display_errors') && !(bool) ini_get('display_errors')) { + // except if we're on a CLI SAPI with log errors enabled and the error_log is empty, in which case errors already go to stderr + if (!(bool) ini_get('log_errors') || PHP_SAPI !== 'cli' || '' !== ini_get('error_log')) { + @ini_set('display_errors', PHP_SAPI === 'cli' ? 'stderr' : '1'); + } + } // Set user defined memory limit if ($memoryLimit = getenv('COMPOSER_MEMORY_LIMIT')) { From 3a2d1c5f9c798cda7131ad20fe42fa0dccd2a8d5 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 11 Dec 2024 09:24:40 +0100 Subject: [PATCH 2/2] Update logic --- bin/composer | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/bin/composer b/bin/composer index 6b9db3aa4..4f6d08f72 100755 --- a/bin/composer +++ b/bin/composer @@ -42,12 +42,11 @@ if (!extension_loaded('iconv') && !extension_loaded('mbstring')) { } if (function_exists('ini_set')) { - // if display_errors is set to stderr or unset, we set it - if ('stderr' !== ini_get('display_errors') && !(bool) ini_get('display_errors')) { - // except if we're on a CLI SAPI with log errors enabled and the error_log is empty, in which case errors already go to stderr - if (!(bool) ini_get('log_errors') || PHP_SAPI !== 'cli' || '' !== ini_get('error_log')) { - @ini_set('display_errors', PHP_SAPI === 'cli' ? 'stderr' : '1'); - } + // check if error logging is on, but to an empty destination - for the CLI SAPI, that means stderr + $logsToSapiDefault = ('' === ini_get('error_log') && (bool) ini_get('log_errors')); + // on the CLI SAPI, ensure errors are displayed on stderr, either via display_errors or via error_log + if (PHP_SAPI === 'cli') { + @ini_set('display_errors', $logsToSapiDefault ? '0' : 'stderr'); } // Set user defined memory limit