Edit report at https://bugs.php.net/bug.php?id=60211&edit=1

 ID:                 60211
 Comment by:         mister dot frb 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:            Class/Object related
 Operating System:   Windows 7 x64
 PHP Version:        5.3.8
 Block user comment: N
 Private report:     N

 New Comment:

Same problem here on PHP 5.2.6-1+lenny13

I could isolate a few interesting things.

the bug seems to depend on the error value. 
set_error_handler('exceptionsHandler', xx ) where xx < 64 (E_COMPILE_ERROR) and 
the error handler will be called (don't know why though, ...). The shutdown 
function is called anyway, but always after the custom error handler.

i don't why it happens, as hinikato said, the documentation says :
"The following error types cannot be handled with a user defined function: 
[...] E_COMPILE_ERROR [...]"

I can understand why no exception can be raised in the error handler though. I 
f we are already in a 'shutting down' state, exceptions cannot be raised.

also, somehow related, i tried to reproduce the bug with a different error :
$undefinedvar->method();

when trying to call a method on a undefined object, 2 errors are raised : a 
notice for the undefined var and a fatal error for calling a method on a non 
object. If your error handler treats E_NOTICE, it will be called but won't be 
able to raise an exception in time. the shutdown function will be called and 
your script stopped. I think there is room for improvement here. Either the 
error handler should be called, or the shutdown function, but not both of them, 
especially if the error handler has broken functionality like the incapacity to 
raise an exception.


Previous Comments:
------------------------------------------------------------------------
[2011-11-03 23:22:41] hinikato at gmail dot com

Changed package for the bug description.

------------------------------------------------------------------------
[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

Reply via email to