PHP class to handle unrecoverable fatal errors. (use Monolog instead)
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



When there is a problem with your web application, you do not want your visitors to see "fatal error" messages. Instead you want to be able to show them a more friendly page telling them what might be wrong or what they should do when they encounter such an error.

Fatal errors in PHP abort your script, but with this library you can add hooks to the shutdown system of PHP. This allows you to show more user-friendly error messages.


PHP 5.3+

Class loading

Library can be loaded by including Execution.php file, it's also psr0 compatible.

// plain old require_once
require_once 'src/Execution/Execution.php';

// symfony2 autoloader
$loader = new \Symfony\Component\ClassLoader\UniversalClassLoader();
    'Execution' => 'vendor/Execution/src',


Call Execution\Execution::setErrorHandler($callback) to initialize. $callback is any valid callback (array, string, closure, invokable object). setErrorHandler registers the necessary handlers with PHP.

Callback should expect one argument, which is associative array having following keys:

[type] => 1
[message] => Call to undefined function a()
[file] => /var/www/app/index.php
[line] => 12

Sample callback:

$callback = function($error) {
  $message = $error['message'];

  echo "This application did not succesfully finish its request. ".
        "The reason was:\n$message\n\n";


The library uses the register_shutdown_function() to allow the catching of fatal errors.


Simply type phpunit tests to run all tests.


Version 1.0 is derivative of ezcExecution package of ezComponents, which was originally developed by Sergey Alexeev, Sebastian Bergmannm, Jan Borsodim, Raymond Bosman, Frederik Holljen, Kore Nordmann, Derick Rethans, Vadym Savchuk, Tobias Schlitt and Alexandru Stanoi.

Major improvements in comparison with original ezcComponent:

  • you can pass any callback, including closures and invokable objects (it is if they have __invoke() method implemented),
  • slimed and simplified,
  • rewritten tests (100% code coverage).

Version 2.0 has been re-written from the scratch with more simplicity in mind. Credits go for my co-worker Paul Kamer, who used this trick in our code.