Silex catches exceptions that are thrown from within a request/response cycle. However, it does not catch PHP errors and notices. This recipe tells you how to catch them by converting them to exceptions.
Symfony/Debug package has an
ErrorHandler class that solves this
problem. It converts all errors to exceptions, and exceptions are then caught
Register it by calling the static
use Symfony\Component\Debug\ErrorHandler; ErrorHandler::register();
It is recommended that you do this as early as possible.
To handle fatal errors, you can additionally register a global
use Symfony\Component\Debug\ExceptionHandler; ExceptionHandler::register();
In production you may want to disable the debug output by passing
use Symfony\Component\Debug\ExceptionHandler; ExceptionHandler::register(false);