Edit report at https://bugs.php.net/bug.php?id=60188&edit=1
ID: 60188 Comment by: hinikato at gmail dot com Reported by: hinikato at gmail dot com Summary: Exception handler and shutdown hanlder were not called after throwing exception Status: Bogus Type: Bug Package: Scripting Engine problem Operating System: Windows 7 x64 PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: Why PHP will not call at least shutdown function in such situtations? Because the engine is in the an unreliable state... What is unreliable state? Is it bug that PHP developers unable to fix due some limitations? Previous Comments: ------------------------------------------------------------------------ [2011-11-02 13:29:57] hinikato at gmail dot com 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 move the respective code fragment to the other file: -- set_error_handler.php -- <?php $foo = new \Foo\MyErrorHandler(); set_error_handler(array($foo, 'errorHandler')); set_exception_handler(array($foo, 'exceptionHandler')); register_shutdown_function(array($foo, 'fatalErrorHandler')); ?> -- end of set_error_handler.php -- then let's modify slightly the our example: -- 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 -- If you will try to run this example you will get the same invalid behavior. ------------------------------------------------------------------------ [2011-11-02 12:12:52] johan...@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php If a fatal error (E_ERROR) is created the engine might be in an unreliable state, we therefore can't all error handlers. Quoting the docs: "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. " http://php.net/set_error_handler ------------------------------------------------------------------------ [2011-11-01 12:10:43] hinikato at gmail dot com Description: ------------ The neither exception handler nor fatal error handler have not been called if error handler throws exception in case of including not existent file using require_once. My PHP version is: PHP Version 5.3.8-ZS5.5.0 Test script: --------------- <?php namespace Foo; class MyErrorHandler { function __construct() { set_error_handler(array($this, 'errorHandler')); set_exception_handler(array($this, 'exceptionHandler')); register_shutdown_function(array($this, 'fatalErrorHandler')); } 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! } } echo '<pre>'; $foo = new MyErrorHandler(); require_once __DIR__ . '/not_existing_file.php'; // file should not exist die(); Expected result: ---------------- Foo\MyErrorHandler::errorHandler Foo\MyErrorHandler::exceptionHandler Foo\MyErrorHandler::fatalErrorHandler 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=60188&edit=1