Download the PHP package jasny/error-handler without Composer
On this page you can find all versions of the php package jasny/error-handler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jasny/error-handler
More information about jasny/error-handler
Files in jasny/error-handler
Informations about the package error-handler
Jasny Error Handler
Error handler with PSR-7 support.
Installation
The Jasny Error Handler package is available on packagist. Install it using composer:
composer require jasny/error-handler
Usage
Just creating an error handler will do nothing. You can use it for logging, handling fatal errors and as PSR-7 compatible middleware.
Logging
By default the error handler with only catch Throwables and not set the php error handler.
To log errors, set the logger using setLogger()
. You can log with any PSR-3 compatible
logger like Monolog.
The logUncaught()
method will set the error handler, so warnings and notices can be logged. It may also register a
shutdown function to handle uncatchable fatal
errors.
PSR-7 compatible middleware
The error handler can be used as PSR-7 compatible (double-pass) middleware.
The error will catch Exceptions and Errors.
You can use this middleware with:
For example use it with Relay:
Or with Jasny Router:
PHP 5 support
With PHP 5 errors aren't thrown, so the middleware won't handle it. To add middleware support for errors in PHP5, you
should call converErrorsToExceptions()
. This method will convert an error to an
ErrorException.
Handling fatal errors
Errors that are not thrown, like syntax errors, are not caught and will cause a fatal error. With the logUncaught()
method, you can specify that the error handler should also these kind of errors.
With the onFatalError()
method you take additional action, like output a pretty error message.
Use true
as second argument of onFatalError
to the output buffer before calling your function.
Combine with other error handlers
Using the error logger might lose backtrace information that other error handlers can pick up. Jasny Error Handler will always call the previous error handler, including the PHP internal error handler for non-thrown errors.
When using Rollbar you should not use the Rollbar handler for Monolog. By using Rollbar's own error handler, you'll get better error reports: