php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40043 Shutdown breaks exception model
Submitted: 2007-01-06 13:33 UTC Modified: 2007-01-06 16:44 UTC
From: public at syranide dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.0 OS: Windows XP 32bit
Private report: No CVE-ID: None
 [2007-01-06 13:33 UTC] public at syranide dot com
Description:
------------
Exceptions is a very nice addition to PHP5, however functions registered with register_shutdown_function breaks this nice exception model.

A function called during shutdown apparently does not have a stack, so when an exception is thrown and is caught by the engine, instead of forwarding the error to the registered exception handler a fatal error is produced detailing nothing of the actual problem, only that the there is no stack.

This is counter-intuitive as to the neat exception model, each function must now internally catch all exceptions and output them.

Suggestion: forward the exception to the registered exception handler (I can't see any problem in this as it is possible to catch the exception yourself and pass it on to the exception handler).

Reproduce code:
---------------
register_shutdown_function('nostack');
function nostack() {
	throw new Exception();
}

Expected result:
----------------
Fatal error:  Uncaught exception 'Exception' in C:\php\test.php:4
Stack trace:
#0 C:\php\test.php(2): nostack()
#1 {main} thrown in C:\php\test.php on line 4

Actual result:
--------------
Fatal error:  Exception thrown without a stack frame in Unknown on line 0

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-06 13:48 UTC] public at syranide dot com
Although not fully on topic, it should be worth mentioning that it is also slightly counter-intuitive that exceptions in shutdown functions completely halts execution, preventing other shutdown functions from executing.

Currently this is also avoidable by catching all exceptions in the shutdown functions themselves, although this would be a nice feature as well.

However I can agree that execution can turn pretty funny having caught multiple exceptions, but personally I think it would benefit the stability of shutdown functions.
 [2007-01-06 16:44 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon May 12 13:01:27 2025 UTC