Codeschnipsel inspiriert von diesem Artikel:
fatalerrorhandler.php
<?php // report all but fatal errors error_reporting((E_ALL | E_STRICT) ^ (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR)); // fatal error handler as shutdown function register_shutdown_function('fatalErrorHandler'); function fatalErrorHandler() { $error = error_get_last(); if ($error['type'] & (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR)) { echo '<h1>Fatal Error, shutting down...</h1>'; echo '<pre>' . var_export($error,true) . '</pre>'; } else { echo 'Regular Shutdown, no fatal errors.'; } }
test1.php
<?php require 'fatalerrorhandler.php'; // Fatal Error (E_ERROR) unknown_function_call();
test2.php
<?php require 'fatalerrorhandler.php'; // E_USER_ERROR trigger_error('...', E_USER_ERROR);
test3.php
<?php require 'fatalerrorhandler.php'; // Notice (E_NOTICE) echo $unknown_var;