This is an old revision of the document!

PHP RFC: Stackable Error Handlers


This RFC tries to address the couple of feedback and possible shortcomings of the current error handler infrastructure, via introducing a stackable error handler infrastructure(similar to the current spl_autoload one), which can be used to extend or replace the default error handler using a stackable API where multiple error handlers can co-exist and only care about their own errors.


There would be a built-in error handler set, which implements the current behavior: - log the errors based on the config (error_reporting, log_error, error_log, etc.) - display the errors based on the config. - provides the $php_errormsg based on the config - this handler is defined for E_ALL

When you call set_error_handler using the old signature the the error handler will replace/shadow any other error handler set via the old signature and they will always come after the built-in handler but before any handler added with the new stackable signature. For example: 1. built-in E_ALL

set_error_handler(function($errno, $errstr, $errfile, $errline, $errcontext){/* do something here */}, E_WARNING) 1. built-in E_ALL 2. old-style E_WARNING

set_error_handler(function($errno, $errstr, $errfile, $errline, $errcontext){/* do something else here */}, E_NOTICE) 1. built-in E_ALL 2. old-style #2 E_NOTICE

The new stackable error handling would only generate and pass the error to the chain of handlers if there is at least one error handler set for that particular error type.

Backward Incompatible Changes

What breaks, and what is the justification for it?

Proposed PHP Version(s)

PHP 5.6 (or next major, if we happen to release a major version after 5.5).

SAPIs Impacted

Describe the impact to CLI, Development web server, embedded PHP etc.

New Constants

Describe any new constants so they can be accurately and comprehensively explained in the PHP documentation.

php.ini Defaults

If there are any php.ini settings then list:

  • hardcoded default values
  • php.ini-development values
  • php.ini-production values

Open Issues

Make sure there are no open issues when the vote starts!

Unaffected PHP Functionality

List existing areas/features of PHP that will not be changed by the RFC.

This helps avoid any ambiguity, shows that you have thought deeply about the RFC's impact, and helps reduces mail list noise.

Future Scope

This sections details areas where the feature might be improved in future, but that are not currently proposed in this RFC.

Proposed Voting Choices

Include these so readers know where you are heading and can discuss the proposed voting options.

Patches and Tests

Links to any external patches and tests go here.

If there is no patch, make it clear who will create a patch, or whether a volunteer to help with implementation is needed.

Make it clear if the patch is intended to be the final patch, or is just a prototype.


Links to external references, discussions or RFCs

Rejected Features

Keep this updated with features that were discussed on the mail lists.

rfc/stackable_error_handler.1363736881.txt.gz · Last modified: 2017/09/22 13:28 (external edit)