Consider the following two PHP (5.4) scripts. Why is the callback passed to register_shutdown_function only invoked when script A is executed, but not when script B is executed?
Script A
set_error_handler(function() {
throw new Exception();
});
register_shutdown_function(function() {
echo "shutdown handler invoked\n";
});
undefined();
// "shutdown handler invoked" IS displayed
Script B
set_error_handler(function() {
throw new Exception();
});
register_shutdown_function(function() {
echo "shutdown handler invoked\n";
});
$undefined->undefined();
// "shutdown handler invoked" IS NOT displayed
It’s a bug—if the callable registered with
set_error_handlerthrows an exception, the shutdown function will not be invoked.In this particular case, the following chain of events happens:
The existing bug reports at https://bugs.php.net/61767 (with patch!) and https://bugs.php.net/60909 have additional details.