|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-07-18 16:14 UTC] bschussek at gmail dot com
Description:
------------
I registered both a custom error handler and a custom shutdown function. When calling require with an invalid filename, the following happens:
1. The "warning" error triggers the handler
2. The "fatal" error fires
3. The shutdown function is called
BUT when the error handler throws an exception, no shutdown function is called. This DOES work when using trigger_error() instead of throwing the exception.
Reproduce code:
---------------
function error_handler()
{
var_dump('ERROR');
throw new Exception('my exception');
}
set_error_handler('error_handler');
function shutdown()
{
var_dump('SHUTDOWN');
}
register_shutdown_function('shutdown');
require 'foobar.php';
Expected result:
----------------
string(5) "ERROR"
Fatal error: Uncaught exception 'Exception' with message 'my exception'
string(8) "SHUTDOWN"
Actual result:
--------------
string(5) "ERROR"
Fatal error: main(): Failed opening required 'foobar.php'
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 11:00:01 2025 UTC |
In reply to Jani: Of course fatal errors are fatal, but my registered error handler should run after the warning, BEFORE the fatal error. If you replace the code throw new Exception('my exception'); with trigger_error(...); instead, you will see that the custom error is triggered correctly. The same is not the case for exceptions.I still don't quite understand this. Shouldn't my above code behave the same way as this code? Code: ----- function shutdown() { var_dump('SHUTDOWN'); } register_shutdown_function('shutdown'); throw new Exception('my exception'); Output: ------- Exception: my exception in ... string(8) "SHUTDOWN" The only code difference is that in the original code the exception was thrown from within the error handler. AND that in the original code the shutdown function was not called.)