|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2012-01-27 18:07 UTC] 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';
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 01:00:01 2025 UTC | 
@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.