From 64c3d8abc8a1e81dec5f32d7ce409e2967ee0030 Mon Sep 17 00:00:00 2001 From: Benni Mack <benni@typo3.org> Date: Fri, 8 Sep 2017 12:00:11 +0200 Subject: [PATCH] [BUGFIX] Fix minor error handler code bugs ErrorHandler has a few minor quirks: 1. the protected property is an integer (bitwise-comparison) but initialized as array 2. small indention and repeatable string introduction 3. human-readable text for E_USER_DEPRECATED missing 4. error handling when no autoloader is available is obsolete. The patch fixes all these minor issues. Resolves: #82375 Releases: master, 8.7 Change-Id: Id6f9616602021e04ac6a50737438253a62da788c Reviewed-on: https://review.typo3.org/54002 Reviewed-by: Andreas Fernandez <typo3@scripting-base.de> Tested-by: Andreas Fernandez <typo3@scripting-base.de> Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Helmut Hummel <typo3@helhum.io> Tested-by: TYPO3com <no-reply@typo3.com> Reviewed-by: Benni Mack <benni@typo3.org> Tested-by: Benni Mack <benni@typo3.org> --- .../core/Classes/Error/ErrorHandler.php | 54 +++++++++---------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/typo3/sysext/core/Classes/Error/ErrorHandler.php b/typo3/sysext/core/Classes/Error/ErrorHandler.php index bdb94c190ffc..e192cdac1ad8 100644 --- a/typo3/sysext/core/Classes/Error/ErrorHandler.php +++ b/typo3/sysext/core/Classes/Error/ErrorHandler.php @@ -28,9 +28,9 @@ class ErrorHandler implements ErrorHandlerInterface /** * Error levels which should result in an exception thrown. * - * @var array + * @var int */ - protected $exceptionalErrors = []; + protected $exceptionalErrors = 0; /** * Whether to write a flash message in case of an error @@ -91,38 +91,32 @@ class ErrorHandler implements ErrorHandlerInterface return true; } $errorLevels = [ - E_WARNING => 'Warning', - E_NOTICE => 'Notice', - E_USER_ERROR => 'User Error', - E_USER_WARNING => 'User Warning', - E_USER_NOTICE => 'User Notice', - E_STRICT => 'Runtime Notice', - E_RECOVERABLE_ERROR => 'Catchable Fatal Error', - E_DEPRECATED => 'Runtime Deprecation Notice' + E_WARNING => 'PHP Warning', + E_NOTICE => 'PHP Notice', + E_USER_ERROR => 'PHP User Error', + E_USER_WARNING => 'PHP User Warning', + E_USER_NOTICE => 'PHP User Notice', + E_STRICT => 'PHP Runtime Notice', + E_RECOVERABLE_ERROR => 'PHP Catchable Fatal Error', + E_USER_DEPRECATED => 'TYPO3 Deprecation Notice', + E_DEPRECATED => 'PHP Runtime Deprecation Notice' ]; - $message = 'PHP ' . $errorLevels[$errorLevel] . ': ' . $errorMessage . ' in ' . $errorFile . ' line ' . $errorLine; + $message = $errorLevels[$errorLevel] . ': ' . $errorMessage . ' in ' . $errorFile . ' line ' . $errorLine; if ($errorLevel & $this->exceptionalErrors) { - // handle error raised at early parse time - // autoloader not available & built-in classes not resolvable - if (!class_exists('stdClass', false)) { - $message = 'PHP ' . $errorLevels[$errorLevel] . ': ' . $errorMessage . ' in ' . basename($errorFile) . - 'line ' . $errorLine; - die($message); - } throw new Exception($message, 1476107295); } switch ($errorLevel) { - case E_USER_ERROR: - case E_RECOVERABLE_ERROR: - $severity = 2; - break; - case E_USER_WARNING: - case E_WARNING: - $severity = 1; - break; - default: - $severity = 0; - } + case E_USER_ERROR: + case E_RECOVERABLE_ERROR: + $severity = 2; + break; + case E_USER_WARNING: + case E_WARNING: + $severity = 1; + break; + default: + $severity = 0; + } $logTitle = 'Core: Error handler (' . TYPO3_MODE . ')'; $message = $logTitle . ': ' . $message; // Write error message to the configured syslogs, @@ -155,7 +149,7 @@ class ErrorHandler implements ErrorHandlerInterface $flashMessage = GeneralUtility::makeInstance( \TYPO3\CMS\Core\Messaging\FlashMessage::class, $message, - 'PHP ' . $errorLevels[$errorLevel], + $errorLevels[$errorLevel], $severity ); /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */ -- GitLab