Edit report at https://bugs.php.net/bug.php?id=60211&edit=1
ID: 60211 User updated by: hinikato at gmail dot com Reported by: hinikato at gmail dot com Summary: register_shutdown_function() not called in combination with set_error_handler() Status: Open Type: Bug -Package: Scripting Engine problem +Package: Class/Object related Operating System: Windows 7 x64 PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: Changed package for the bug description. Previous Comments: ------------------------------------------------------------------------ [2011-11-03 13:26:28] hinikato at gmail dot com Please note that error handler will be called because the require_once triggers the E_WARNING first, but shutdown function and exception handler will not be called at all. This bug prevents from writing the following code also, because exceptions is not determined for some reason: try { require_once __DIR__ . '/not_existing_file.php'; // file should not exist } catch (\Exception $e) { echo $e->getMessage(); // will not be called! } And this bug prevents from logging fatal errors in our shutdown function if we log them in it. ------------------------------------------------------------------------ [2011-11-03 13:10:40] hinikato at gmail dot com Description: ------------ My PHP version is: PHP Version 5.3.8-ZS5.5.0, but this bug exist in the Linux environment also. Checked in Debian with PHP 5.3.8. In the set_error_handler() documentation we have the following quote: "The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called." According this quote the bug should not occur if specified error types will not be raised in the file where set_error_handler() is called. Let's try to implement such condition. Test script: --------------- -- set_error_handler.php -- <?php $foo = new \Foo\MyErrorHandler(); set_error_handler(array($foo, 'errorHandler')); // we call the set_error_handler() in the other file. set_exception_handler(array($foo, 'exceptionHandler')); register_shutdown_function(array($foo, 'fatalErrorHandler')); ?> -- end of set_error_handler.php -- -- bug -- namespace Foo; class MyErrorHandler { function errorHandler() { echo __METHOD__ . "\n"; throw new \Exception('test'); } function exceptionHandler() { echo __METHOD__ . "\n"; // should be called! } function fatalErrorHandler() { echo __METHOD__ . "\n"; // should be called! } } require_once __DIR__ . '/set_error_handler.php'; require_once __DIR__ . '/not_existing_file.php'; // file should not exist die(); -- end of bug -- Expected result: ---------------- Foo\MyErrorHandler::errorHandler Foo\MyErrorHandler::exceptionHandler Foo\MyErrorHandler::fatalErrorHandler // should be called at least! Fatal error: main() [function.require]: Failed opening required 'X:\home\localhost\www/not_existing_file.php' (include_path='D:\system\home\projects\myak\www\includes') in X:\home\localhost\www\test.php on line 28 Actual result: -------------- Foo\MyErrorHandler::errorHandler Fatal error: main() [function.require]: Failed opening required 'X:\home\localhost\www/not_existing_file.php' (include_path='D:\system\home\projects\myak\www\includes') in X:\home\localhost\www\test.php on line 28 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60211&edit=1