ErrorHandler
class ErrorHandler
A generic ErrorHandler for the PHP engine.
Provides five bit fields that control how errors are handled: - thrownErrors: errors thrown as \ErrorException - loggedErrors: logged errors, when not @-silenced - scopedErrors: errors thrown or logged with their local context - tracedErrors: errors logged with their stack trace - screamedErrors: never @-silenced errors
Each error level can be logged by a dedicated PSR-3 logger object. Screaming only applies to logging. Throwing takes precedence over logging. Uncaught exceptions are logged as E_ERROR. E_DEPRECATED and E_USER_DEPRECATED levels never throw. E_RECOVERABLE_ERROR and E_USER_ERROR levels always throw. Non catchable errors that can be detected at shutdown time are logged when the scream bit field allows so. As errors have a performance cost, repeated errors are all logged, so that the developer can see them and weight them as more important to fix than others of the same level.
Methods
Sets a logger to non assigned errors levels.
Sets a logger for each error level.
Sets a user exception handler.
Sets the PHP error levels that throw an exception when a PHP error occurs.
Sets the PHP error levels for which local variables are preserved.
Sets the PHP error levels for which the stack trace is preserved.
Sets the error levels where the @-operator is ignored.
Handles errors by filtering then logging them according to the configured bit fields.
Handles an exception by logging then forwarding it to another handler.
Shutdown registered function for handling PHP fatal errors.
Gets the fatal error handlers.
Details
static ErrorHandler
register(ErrorHandler $handler = null, bool $replace = true)
Registers the error handler.
setDefaultLogger(LoggerInterface $logger, array|int $levels = E_ALL, bool $replace = false)
Sets a logger to non assigned errors levels.
int
throwAt(int $levels, bool $replace = false)
Sets the PHP error levels that throw an exception when a PHP error occurs.
int
scopeAt(int $levels, bool $replace = false)
Sets the PHP error levels for which local variables are preserved.
int
traceAt(int $levels, bool $replace = false)
Sets the PHP error levels for which the stack trace is preserved.
int
screamAt(int $levels, bool $replace = false)
Sets the error levels where the @-operator is ignored.
bool
handleError(int $type, string $message, string $file, int $line)
Handles errors by filtering then logging them according to the configured bit fields.
handleException(Exception|Throwable $exception, array $error = null)
Handles an exception by logging then forwarding it to another handler.
static
handleFatalError(array $error = null)
Shutdown registered function for handling PHP fatal errors.
protected FatalErrorHandlerInterface[]
getFatalErrorHandlers()
Gets the fatal error handlers.
Override this method if you want to define more fatal error handlers.