error
error copied to clipboard
Makes handling and debugging PHP errors suck less
Error handler #############
Makes handling and debugging PHP errors suck less.
.. image:: https://travis-ci.com/kuria/error.svg?branch=master :target: https://travis-ci.com/kuria/error
|Web error screen in debug mode|
.. contents:: :depth: 2
Features
-
normal / debug mode
-
converts PHP errors (warnings, notices, etc.) into exceptions
-
respects the global
error_reportingsetting -
handles uncaught exceptions and fatal errors (including parse and out-of-memory errors)
-
CLI error screen writes errors to stderr
-
web error screen renders errors for web browsers
-
| normal mode shows a generic error message: | |Web error screen in normal mode|
-
| debug mode shows all available info: | |Web error screen in debug mode|
- file paths and line numbers
- highlighted code previews
- stack traces
- argument lists
- output buffer (can be shown as HTML too)
- plaintext trace (for copy-paste)
-
-
event system that can be utilised to:
- implement logging
- suppress or force errors conditionally
- change or add content to the error screens
Requirements
- PHP 7.1+
Usage example
.. code:: php
setDebug($debug); $errorHandler->register(); // trigger an error to see the error handler in action echo $invalidVariable; Event system ************ Error handler events ==================== Possible events emitted by the ``ErrorHandler`` class are listed in ``ErrorHandlerEvents``: ``ErrorHandlerEvents::ERROR`` ----------------------------- Emitted when a PHP errors occurs. Arguments: 1. ``Kuria\Error\Exception\ErrorException $exception`` - you may use the ``suppress()`` or ``force()`` method to suppress or force the exception, respectivelly, regardless of the ``error_reporting`` PHP setting 2. ``bool $debug`` ``ErrorHandlerEvents::EXCEPTION`` --------------------------------- Emitted when an uncaught exception or a fatal error is being handled. Arguments: 1. ``Throwable $exception`` 2. ``bool $debug`` .. WARNING:: Avoid performing memory-intensive tasks in listeners of this event if ``$exception`` is an instance of ``Kuria\Error\Exception\OutOfMemoryException``. ``ErrorHandlerEvents::FAILURE`` ------------------------------- Emitted when an uncaught exception or a fatal error could not be handled. This can happen when an ``exception`` event listener or the registered error screen throws an additional exception. Throwing another exception or causing a fatal error at this point will just kill the script. Arguments: 1. ``Throwable $exception`` 2. ``bool $debug`` .. WARNING:: Avoid performing memory-intensive tasks in listeners of this event if ``$exception`` is an instance of ``Kuria\Error\Exception\OutOfMemoryException``. Web error screen events ======================= Possible events emitted by the ``WebErrorScreen`` class are listed in ``WebErrorScreenEvents``: ``WebErrorScreenEvents::RENDER`` -------------------------------- Emitted when rendering in normal mode. Receives an array with the following keys: - ``&title``: used in ``