Bug #60909 [Opn->Csd]: custom error handler throwing Exception + fatal error = no shutdown function
| From: | dmitry@php.net | Date: | Thu, 06 Sep 2012 10:04:36 +0000 |
| Subject: | Bug #60909 [Opn->Csd]: custom error handler throwing Exception + fatal error = no shutdown function | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-173206@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60909&edit=1
ID: 60909
Updated by: dmitry@php.net
Reported by: tyrael@php.net
Summary: custom error handler throwing Exception + fatal
error = no shutdown function
-Status: Open
+Status: Closed
Type: Bug
Package: Scripting Engine problem
Operating System: linux
PHP Version: 5.4.0RC6
-Assigned To:
+Assigned To: dmitry
Block user comment: N
Private report: N
New Comment:
This bug has been fixed in SVN.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
For Windows:
http://windows.php.net/snapshots/
Thank you for the report, and for helping us make PHP better.
The same as #61767.
Previous Comments:
------------------------------------------------------------------------
[2012-09-06 10:04:05] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b29dc146b9311c14186c14bcb1c8ae5288b65d73
Log: - Fixed bug #61767 (Shutdown functions not called in certain error situation) - Fixed bug
#60909 (custom error handler throwing Exception + fatal error = no shutdown function)
------------------------------------------------------------------------
[2012-09-04 16:24:29] bishop@php.net
@nikic: I can generate the same path without the first non-fatal error:
----------------------------------------------------------------------
register_shutdown_function(function(){echo("\n\n!!!shutdown!!!\n\n");});
set_error_handler(function($errno, $errstr, $errfile, $errline){throw new
Exception("Foo");});
class Bad {
public function __toString() {
throw new Exception('Oops, I cannot do this');
}
}
$bad = new Bad();
echo "$bad";
----------------------------------------------------------------------
This is on 5.3.10, like @jpauli report, and 5.4.6 as well.
The @laruence EG(exception) = NULL patch handles this case as well. AFAIK, that patch is
appropriate.
------------------------------------------------------------------------
[2012-04-20 00:15:50] nikic@php.net
I tried adding an EG(exception) = NULL; at the start of php_request_shutdown() and it indeed fixes
the issue. Though probably that's not the right way to fix this.
------------------------------------------------------------------------
[2012-04-19 23:40:57] nikic@php.net
So, this is what I think is happening here:
1. The first non-fatal error (here warning) throws an Exception, i.e. sets EG(exception)
2. The second fatal error then causes a zend_bailout() moving us directly to php_request_shutdown()
3. During the shutdown sequence PHP will try to call the shutdown handler using
call_user_function().
4. As EG(exception) is still set, the call is not allows (see http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_execute_API.c#775).
------------------------------------------------------------------------
[2012-04-19 23:06:26] nikic@php.net
Together with https://bugs.php.net/bug.php?id=61767 it is a bit
more clear under which circumstances this occurs:
1. A non-fatal error is thrown
2. The error handler throws an Exception
3. A fatal error is thrown
In this particular case:
1. require() throws an E_WARNING (Warning: require(notfound.php): failed to open stream: No such
file or directory).
2. The error handler throws the Exception
3. require() throws an E_COMPILE_ERROR (Fatal error: require(): Failed opening required
'notfound.php')
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=60909
--
Edit this bug report at https://bugs.php.net/bug.php?id=60909&edit=1