diff --git a/system/Debug/BaseExceptionHandler.php b/system/Debug/BaseExceptionHandler.php index 4305265d2d2c..cc2200b7a440 100644 --- a/system/Debug/BaseExceptionHandler.php +++ b/system/Debug/BaseExceptionHandler.php @@ -268,4 +268,16 @@ protected function render(Throwable $exception, int $statusCode, $viewFile = nul return ob_get_clean(); })(); } + + /** + * Whether the PHP display_errors setting is enabled. + */ + protected function isDisplayErrorsEnabled(): bool + { + return in_array( + strtolower(ini_get('display_errors')), + ['1', 'true', 'on', 'yes'], + true + ); + } } diff --git a/system/Debug/ExceptionHandler.php b/system/Debug/ExceptionHandler.php index d6f97b76a32b..415226108f62 100644 --- a/system/Debug/ExceptionHandler.php +++ b/system/Debug/ExceptionHandler.php @@ -76,7 +76,7 @@ public function handle( } if (! str_contains($request->getHeaderLine('accept'), 'text/html')) { - $data = (ENVIRONMENT === 'development' || ENVIRONMENT === 'testing') + $data = $this->isDisplayErrorsEnabled() ? $this->collectVars($exception, $statusCode) : ''; @@ -134,13 +134,7 @@ protected function determineView( // Production environments should have a custom exception file. $view = 'production.php'; - if ( - in_array( - strtolower(ini_get('display_errors')), - ['1', 'true', 'on', 'yes'], - true - ) - ) { + if ($this->isDisplayErrorsEnabled()) { $view = 'error_exception.php'; } diff --git a/user_guide_src/source/changelogs/v4.5.6.rst b/user_guide_src/source/changelogs/v4.5.6.rst index 9490e62e4e80..f59885387a3f 100644 --- a/user_guide_src/source/changelogs/v4.5.6.rst +++ b/user_guide_src/source/changelogs/v4.5.6.rst @@ -42,6 +42,7 @@ Bugs Fixed - **Validation:** Fixed a bug where complex language strings were not properly handled. - **CURLRequest:** Added support for handling proxy responses using HTTP versions other than 1.1. - **Database:** Fixed a bug that caused ``Postgre\Connection::reconnect()`` method to throw an error when the connection had not yet been established. +- **Exception:** Fixed a bug where exceptions for non-HTML responses were not relying on the PHP ``display_errors`` setting. See the repo's `CHANGELOG.md `_