From:             
Operating system: Win7
PHP version:      5.4.0
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:Shutdown functions not called in certain error situation

Description:
------------
I am using register_shutdown_function() toghether with error_get_last() and
set_error_handler() to "handle" fatal errors (to display message in debug
screen etc, details do not matter).

Everything works perfectly except for one specific scenario - If there is
an error caused by calling a method on UNDEFINED (really undefined, not
null etc) variable, then the following happens (NOT OK, UNEXPECTED):

 1. registered error_handler is invoked for E_NOTICE (undefined variable) 
 2. the error_handler throws an ErrorException
 3. the exception gets *eaten* by something, it never makes it out of the
error_handler
 4. PHP exits with FATAL error (Call to a member function foo() on a
non-object)
 5. No shutdown functions get called

----

If the variable is not UNDEFINED but just not an object (e.g. null),
everything happens as follows (ALL OK, EXPECTED):

 1. PHP exits with FATAL error (Call to a member function foo() on a
non-object)
 2. Registered shutdown functions are called

----

If I return TRUE from the error_handler, following happens (OK, BUT NOT
ACCEPTABLE):

 1. registered error_handler is invoked for E_NOTICE (undefined variable) 
 2. the error_handler returns TRUE
 3. PHP exits with FATAL error (Call to a member function foo() on a
non-object)
 4. Registered shutdown functions are called

Test script:
---------------
set_error_handler(function($code, $msg, $file = null, $line = null) {
    echo "Error handler called\n";
    throw new \ErrorException($msg, $code, 0, $file, $line);
});

register_shutdown_function(function(){
    echo "Shutting down\n";
    print_r(error_get_last());
});

// $undefined = null; // defined variable does not cause problems
$undefined->foo();

Expected result:
----------------
Fatal error: Call to a member function foo() on a non-object in _example_
on line 14
Shutting down Array ( [type] => 1 [message] => Call to a member function
foo() on a non-object [file] => _example_ [line] => 14 ) 

Actual result:
--------------
Error handler called
Fatal error: Call to a member function foo() on a non-object in _example_
on line 13


-- 
Edit bug report at https://bugs.php.net/bug.php?id=61767&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=61767&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=61767&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=61767&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=61767&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=61767&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=61767&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=61767&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=61767&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=61767&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=61767&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=61767&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=61767&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=61767&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=61767&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=61767&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=61767&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=61767&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=61767&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=61767&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=61767&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=61767&r=mysqlcfg

Reply via email to