Bug #60909 [Com]: custom error handler throwing Exception + fatal error = no shutdown function
Edit report at https://bugs.php.net/bug.php?id=60909&edit=1
ID: 60909
Comment by: nikic@php.net
Reported by: tyrael@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:
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')
Previous Comments:
------------------------------------------------------------------------
[2012-02-09 14:33:57] jpauli@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] tyrael@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=60909&edit=1
Thread (7 messages)