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, only once for repeated errors - 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 EERROR. EDEPRECATED and EUSERDEPRECATED levels never throw. ERECOVERABLEERROR and EUSERERROR 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
static ErrorHandler | register(ErrorHandler $handler = null, bool $replace = true) Registers the error handler. | |
__construct(BufferingLogger $bootstrappingLogger = null) | ||
setDefaultLogger(LoggerInterface $logger, array|int $levels = E_ALL, bool $replace = false) Sets a logger to non assigned errors levels. | ||
array | setLoggers(array $loggers) Sets a logger for each error level. | |
callable|null | setExceptionHandler(callable $handler = null) Sets a user exception handler. | |
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, array $context, array $backtrace = null) 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. | |
static | stackErrors() Configures the error handler for delayed handling. | |
static | unstackErrors() Unstacks stacked errors and forwards to the logger. |
Details
static ErrorHandler register(ErrorHandler $handler = null, bool $replace = true)
Registers the error handler.
__construct(BufferingLogger $bootstrappingLogger = null)
setDefaultLogger(LoggerInterface $logger, array|int $levels = E_ALL, bool $replace = false)
Sets a logger to non assigned errors levels.
array setLoggers(array $loggers)
Sets a logger for each error level.
callable|null setExceptionHandler(callable $handler = null)
Sets a user exception handler.
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, array $context, array $backtrace = null)
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.
static stackErrors()
Configures the error handler for delayed handling.
Ensures also that non-catchable fatal errors are never silenced.
As shown by http://bugs.php.net/42098 and http://bugs.php.net/60724 PHP has a compile stage where it behaves unusually. To workaround it, we plug an error handler that only stacks errors for later.
The most important feature of this is to prevent autoloading until unstackErrors() is called.
static unstackErrors()
Unstacks stacked errors and forwards to the logger.
Please login to continue.