It's my understanding that register_shutdown_function is a 'valid' manner in which to catch top level errors in PHP, as noted here.
Now - I've got a rather full error handling implementation that I hope to force to catch EVERY error that PHP generates after initialization. My code to do so looks something like this:
// ErrorInitialization.php
if($GLOBALS["EnableReporting"])
error_reporting($GLOBALS["ErrorLevel"]);
else
error_reporting(0);
ini_set('display_errors',$GLOBALS["EnableReporting"]);
ini_set('display_startup_errors',$GLOBALS["EnableReporting"]);
set_error_handler($GLOBALS["ErrorCallback"]);
set_exception_handler($GLOBALS["ExceptionCallback"]);
register_shutdown_function($GLOBALS["FatalCallback"]);
For the sake of being thorough; here are my globals as defined:
// Config.php - Required from global scope.
$ErrorCallback = "HandleRuntimeError";
$ExceptionCallback = "HandleException";
$FatalCallback = "HandleFatalError";
$EnableReporting = true;
$ErrorLevel = E_ALL;
And furthermore; my actual methods meant to catch said errors:
// ErrorHandling.php
function HandleRuntimeError($ErrorLevel,$ErrorMessage,$ErrorFile,$ErrorLine,$ErrorContext)
{
}
function HandleException($Exception)
{
}
function HandleFatalError()
{
$Error = error_get_last();
// Pass fatal errors up to the standard error callback.
$GLOBALS["ErrorCallback"]($Error['type'],$Error['message'],$Error['file'],$Error['line']);
}
Now - the way I see it at this point I should be getting effectively no output in the event of an error ( since my 'handlers' are empty ); but I am in fact still getting 'standard' reporting - the example being:
Fatal error: require(): Failed opening required '***/resource/php/startup/IncludeHandler.php' (include_path='.;C:\php\pear') in ***\index.php on line 18
Which; again for the sake of being thorough - looks something like this:
// index.php
function Initialize()
{
require($GLOBALS["PHPRoot"] . "errors/ErrorHandling.php");
require($GLOBALS["PHPRoot"] . "errors/ErrorInitialization.php");
require($GLOBALS["PHPRoot"] . "startup/IncludeHandler.php"); // Line 18
}
Moral of the story: Does anyone have a quick answer as to why the 'HandleFatalError' method isn't getting called?
-- Am I screwing myself over by turning display_errors on?