SPHPlayground API
SPHPlayground
sphplayground sphplayground

Error and Exception handling

BASIC INFORMATION:

PHP 7 changed how most errors are reported by PHP. Instead of reporting errors through the traditional error reporting mechanism used by PHP 5, most errors are now reported by throwing Throwable exceptions and errors. [1]

Any Throwable can be catched by using 'try/catch blocks. If there are no matching blocks, then any default exception handler installed with set_exception_handler() will be called, and if there is no default exception handler, then the exception will be converted to a fatal error and will be handled like a traditional error.

ErrorDispatcher object to manage PHP error and exception listeners

This class can manage both PHP errors and uncaught Throwable objects.

ErrorDispatcher as PHP Error manager

An ErrorDispatcher object replaces PHP's native error handler and sends PHP errors to its error listeners. An Error listener must be a callable or of ErrorListener type.

All of the following PHP error types cannot be handled by an ErrorDispatcher instance

ErrorDispatcher as a Uncaught Throwable handler

In PHP 7, most errors are reported by throwing Error exceptions. Both Error and Exception implements the Throwable interface.

An Exception listener must be a callable or of ExceptionListener type.

NOTE: It is important to note that Script execution will stop after a handler is called.

Viewing and debugging PHP errors and exceptions

Exceptions, Errors,and Warnings can be viewed with classes in this namespace

Improper handling of errors can introduce a variety of security problems for a web site. The most common problem is when detailed internal error messages such as stack traces, database dumps, and error codes are displayed to the user. These messages reveal implementation details that should never be revealed. Such details can provide hackers important clues on potential flaws in the site and such messages are also disturbing to normal users. [2]