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.
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) 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. | |
FatalErrorHandlerInterface[] | getFatalErrorHandlers() Gets the fatal error handlers. |
Registers the error handler.
ErrorHandler | $handler | The handler to register |
bool | $replace | Whether to replace or not any existing handler |
ErrorHandler | The registered error handler |
BufferingLogger | $bootstrappingLogger |
Sets a logger to non assigned errors levels.
LoggerInterface | $logger | A PSR-3 logger to put as default for the given levels |
array|int | $levels | An array map of E_* to LogLevel::* or an integer bit field of E_* constants |
bool | $replace | Whether to replace or not any existing logger |
Sets a logger for each error level.
array | $loggers | Error levels to [LoggerInterface|null, LogLevel::*] map |
array | The previous map |
InvalidArgumentException |
Sets a user exception handler.
callable | $handler | A handler that will be called on Exception |
callable|null | The previous exception handler |
Sets the PHP error levels that throw an exception when a PHP error occurs.
int | $levels | A bit field of E_* constants for thrown errors |
bool | $replace | Replace or amend the previous value |
int | The previous value |
Sets the PHP error levels for which local variables are preserved.
int | $levels | A bit field of E_* constants for scoped errors |
bool | $replace | Replace or amend the previous value |
int | The previous value |
Sets the PHP error levels for which the stack trace is preserved.
int | $levels | A bit field of E_* constants for traced errors |
bool | $replace | Replace or amend the previous value |
int | The previous value |
Sets the error levels where the @-operator is ignored.
int | $levels | A bit field of E_* constants for screamed errors |
bool | $replace | Replace or amend the previous value |
int | The previous value |
Handles errors by filtering then logging them according to the configured bit fields.
int | $type | One of the E_* constants |
string | $message | |
string | $file | |
int | $line |
bool | Returns false when no handling happens so that the PHP engine can handle the error itself |
ErrorException | When $this->thrownErrors requests so |
Handles an exception by logging then forwarding it to another handler.
Exception|Throwable | $exception | An exception to handle |
array | $error | An array as returned by error_get_last() |
Shutdown registered function for handling PHP fatal errors.
array | $error | An array as returned by error_get_last() |
Gets the fatal error handlers.
Override this method if you want to define more fatal error handlers.
FatalErrorHandlerInterface[] | An array of FatalErrorHandlerInterface |
© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Component/Debug/ErrorHandler.html