|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-11-01 12:10 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 16 09:00:02 2025 UTC |
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.