Description
With PHP 7, \Error
exceptions are logged two times as critical.
Here an example of the TypeEror
.
- CRITICAL - Type error: Argument 1 passed to Symfony\Component\HttpFoundation\Request::getPreferredLanguage() must be of the type array, string given, called in src\AppBundle\Controller\DefaultController.php on line 17
- CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError: "Type error: Argument 1 passed to Symfony\Component\HttpFoundation\Request::getPreferredLanguage() must be of the type array, string given, called in src\AppBundle\Controller\DefaultController.php on line 17" at src\Symfony\Component\HttpFoundation\Request.php line 1535
The reason for this is that the ErrorHandler::handleException
logs the PHP error exception. It than wraps the Throwable in a FatalThrowableError
to let the Kernel exception listeners do their work (which are typehinted against \Exception
, see GetResponseForExceptionEvent
). Then the ExceptionListener
kicks in, which logs the FatalThrowableError
again.
One error should not cause multiple error logs. Also the second error log with Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError
is kinda wrong/irritating because you cannot actually catch the FatalThrowableError
. You have to catch the \Error
or \Throwable
instead.
This double logging is in dev environment. In prod env only the second wrong error "Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError" is logged.