#48969 [Asn]: register_shutdown_function() buggy in combination with set_error_handler()

From: Date: Tue, 21 Jul 2009 12:43:38 +0000
Subject: #48969 [Asn]: register_shutdown_function() buggy in combination with set_error_handler()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-140001@lists.php.net to get a copy of this message
ID: 48969 Updated by: jani@php.net Reported By: bschussek at gmail dot com Status: Assigned Bug Type: Scripting Engine problem Operating System: Linux Ubuntu 9.04 PHP Version: 5.2.10 Assigned To: dmitry New Comment: 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. :) Previous Comments: ------------------------------------------------------------------------ [2009-07-20 11:43:33] 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'); with trigger_error(...); instead, you will see that the custom error is triggered correctly. The same is not the case for exceptions. ------------------------------------------------------------------------ [2009-07-20 11:12:34] derick@php.net 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 10:57:29] jani@php.net FATAL errors are fatal, the execution of the scripts ends at those. No bug here. ------------------------------------------------------------------------ [2009-07-18 16:14:55] 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' ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48969&edit=1

« previous php.bugs (#140001) next »