|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #48969 register_shutdown_function() buggy in combination with set_error_handler()
Submitted: 2009-07-18 16:14 UTC Modified: 2010-01-13 02:11 UTC
From: bschussek at gmail dot com Assigned: kalle (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.2.10 OS: Linux Ubuntu 9.04
Private report: No CVE-ID: None
 [2009-07-18 16:14 UTC] bschussek at gmail dot com
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()
  throw new Exception('my exception');

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'


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-20 10:57 UTC]
FATAL errors are fatal, the execution of the scripts ends at those. No bug here.
 [2009-07-20 11:12 UTC]
I am reopening this. Because even with fatal errors, the shutdown handler should run. It always has so if that changes it is a BC break. Assigning to Dmitry.
 [2009-07-20 11:43 UTC] bschussek at gmail dot com
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');



instead, you will see that the custom error is triggered correctly. The same is not the case for exceptions.
 [2009-07-21 12:43 UTC]
It's not really buggy, you just can't call user functions when there are uncatched exceptions thrown. Comment in sources say it would otherwise cause instable executor. So instead of crashing, it just won't run your function. :)
 [2009-07-21 12:46 UTC]
See also bug #30266 for which this fix was added. Commit log mentions a possibility of throwing E_FATAL error for this but leaves that to be discussed. I guess it was never discussed. :)
 [2009-07-21 12:50 UTC]
One more thing: The shutdown func WILL be run. As long as there are no uncaught exceptions left.
 [2009-07-21 12:58 UTC]
This is really documentation issue. You can't call _any_ user callbacks (f.e. using call_user_func() & such) when there are uncaught exceptions.
 [2009-07-21 13:25 UTC] bschussek at gmail dot com
I still don't quite understand this. Shouldn't my above code behave the same way as this code?

function shutdown()

throw new Exception('my exception');

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.)
 [2010-01-13 02:09 UTC]
Automatic comment from SVN on behalf of kalle
Log: Fixed bug #48969 (register_shutdown_function() buggy in combination with set_error_handler())
 [2010-01-13 02:11 UTC]
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

 [2012-07-17 02:24 UTC] josh at jj88 dot org
See and
id=61767 for additional information.
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Jul 17 22:01:26 2019 UTC