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, 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
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.
Configures the error handler for delayed handling.
Unstacks stacked errors and forwards to the logger.
Details
at line line 109
static ErrorHandler
register(ErrorHandler $handler = null, bool $replace = true)
Registers the error handler.
at line line 139
__construct(BufferingLogger $bootstrappingLogger = null)
at line line 154
setDefaultLogger(LoggerInterface $logger, array|int $levels = null, bool $replace = false)
Sets a logger to non assigned errors levels.
at line line 188
array
setLoggers(array $loggers)
Sets a logger for each error level.
at line line 239
callable|null
setExceptionHandler(callable $handler = null)
Sets a user exception handler.
at line line 255
int
throwAt(int $levels, bool $replace = false)
Sets the PHP error levels that throw an exception when a PHP error occurs.
at line line 275
int
scopeAt(int $levels, bool $replace = false)
Sets the PHP error levels for which local variables are preserved.
at line line 294
int
traceAt(int $levels, bool $replace = false)
Sets the PHP error levels for which the stack trace is preserved.
at line line 313
int
screamAt(int $levels, bool $replace = false)
Sets the error levels where the @-operator is ignored.
at line line 354
bool
handleError($type, $message, $file, $line, array $context, array $backtrace = null)
Handles errors by filtering then logging them according to the configured bit fields.
at line line 482
handleException(Exception|Throwable $exception, array $error = null)
Handles an exception by logging then forwarding it to another handler.
at line line 549
static
handleFatalError(array $error = null)
Shutdown registered function for handling PHP fatal errors.
at line line 609
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.
at line line 617
static
unstackErrors()
Unstacks stacked errors and forwards to the logger.