Edit report at https://bugs.php.net/bug.php?id=60909edit=1
ID: 60909
Updated by: bis...@php.net
Reported by:tyr...@php.net
Summary:custom error handler throwing Exception + fatal
error = no shutdown function
Status: Open
Type: Bug
Package:Scripting Engine problem
Operating System: linux
PHP Version:5.4.0RC6
Block user comment: N
Private report: N
New Comment:
@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.
Previous Comments:
[2012-04-20 00:15:50] ni...@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] ni...@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] ni...@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')
[2012-02-09 14:33:57] jpa...@php.net
Ok I can reproduce.
Try replacing your require (which generates E_COMPILE_ERROR) by an unknown
function call (which generates E_ERROR), and all's just fine
So there is a trick in the error engine, any kind of fatal shouldn't be handled
by user defined error handlers, here we got proof it's not the case
Tip: Reproduced on 5.3.10 as well
[2012-01-27 18:07:20] tyr...@php.net
Description:
first of all sorry for the weird Summary, I couldn't come up with a better one.
it is weird.
so it seems that if you have a shutdown function callback set and a custom
error
handler which would throw and exception and you happen to have a fatal error,
the shutdown function won't be called.
See the attached script, the error handler shouldn't really do anything here,
because it won't be called for the fatals, but somehow it still screw things up.
If I remove the error handler, I will see the !!!shutdown!!! printed.
If I put a return false; before the throw I will see the !!!shutdown!!!
printed.
If I add E_NOTICE as the $error_type to the set_error_handler call I will see
the !!!shutdown!!! printed.
If I add E_WARNING as the $error_type to the set_error_handler call I will NOT
see the !!!shutdown!!! printed.
wtf?
Test script:
---
?php
register_shutdown_function(function(){echo(\n\n!!!shutdown!!!\n\n);});
set_error_handler(function($errno, $errstr, $errfile, $errline){throw new
Exception(Foo);});
require 'notfound.php';
--
Edit this bug report at https://bugs.php.net/bug.php?id=60909edit=1