From 1b799579d98443374312676e23e93ccaa186110a Mon Sep 17 00:00:00 2001 From: "Thomas A. Hirsch" Date: Mon, 19 Feb 2024 20:46:23 +0100 Subject: [PATCH] Backported display_errors-handling to sf1 --- .../sfApplicationConfiguration.class.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/config/sfApplicationConfiguration.class.php b/lib/config/sfApplicationConfiguration.class.php index e2bcba6f7..0baa1a595 100644 --- a/lib/config/sfApplicationConfiguration.class.php +++ b/lib/config/sfApplicationConfiguration.class.php @@ -128,7 +128,23 @@ public function initConfiguration() } // error settings - ini_set('display_errors', $this->isDebug() ? 'on' : 'off'); + // Based on the debug setting ($this->isDebug()), it controls if errors should be displayed + // (display_errors). If the application is not in the debug mode or if it's running in a + // CLI, PHPDBG, or embed server API, then errors are not displayed (display_errors is set + // to 0). However, if the application is in debug mode and errors are not already logged to + // the error log, then errors are displayed (display_errors is set to 1). + if ( + !$this->isDebug() + || !in_array(PHP_SAPI, array('cli', 'phpdbg', 'embed'), true) + ) { + ini_set('display_errors', 0); + } elseif ( + !filter_var(ini_get('log_errors'), FILTER_VALIDATE_BOOLEAN) + || ini_get('error_log') + ) { + // CLI - display errors only if they're not already logged to STDERR + ini_set('display_errors', 1); + } error_reporting(sfConfig::get('sf_error_reporting')); // initialize plugin configuration objects