From:             
Operating system: Windows 7
PHP version:      5.3.4
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:ASSERT_BAIL seems to interfer with custom error-handling

Description:
------------
I seem to have encountered an unexpected interaction between my custom
error-handling setup and enabling the ASSERT_BAIL option.



The (simplified) situation is as follows:



* A custom error_handler() is defined and it "converts" all non-fatal PHP
errors into ErrorException's.

* A custom assert_handler() is defined to display all failed assertions.

* The script in question has ASSERT_BAIL enabled and error reporting set to
"E_ALL".



See the reproduce code for an example.



An assertion containing an E_NOTICE type error is constructed. When
executed under the above conditions, execution halts the moment
error_handler() throws its ErrorException.

When ASSERT_BAIL is disabled, the custom error_handler() throws its
ErrorException which is "caught" by PHP and results in a fatal error.



I would assume ASSERT_BAIL to only bail if/when the assertion gets the
chance to be handled. When the custom error_handler() is modified to _not_
throw an exception, but only provide some output, execution continues to
assert_handler() after which ASSERT_BAIL is respected.



The above behaviour is somewhat "killing" in situations where the actual
error_handler() does nothing but throw an exception and expects a further
custom exception-handler to pick up the pieces. The situation as sketched
above then simply generates no output.

Test script:
---------------
function error_handler($severity, $message, $file, $line){



        echo "Error: $message" . PHP_EOL;

        throw new ErrorException($message);

}



function assert_handler($file, $line, $expression){



        echo "Assertion failed: $expression" . PHP_EOL;

}



set_error_handler('error_handler', E_ALL);



assert_options(ASSERT_CALLBACK, 'assert_handler');

assert_options(ASSERT_BAIL, true);



assert('$foo instanceof Bar');



echo '*Not executed*' . PHP_EOL;

Expected result:
----------------
Error: Undefined variable: foo



Fatal error: Uncaught exception 'ErrorException' with message 'Undefined
variable: foo' in ...

Actual result:
--------------
Error: Undefined variable: foo





For further reference, here's what happens if error_handler() is modified
to _not_ throw an exception:



ASSERT_BAIL enabled:



Error: Undefined variable: foo (<- error_handler())

Assertion failed: $foo instanceof Bar (<- assert_handler())

Error: assert(): Assertion "$foo instanceof Bar" failed (<-
ASSERT_WARNING)



ASSERT_BAIL disabled:



Error: Undefined variable: foo (<- error_handler())

Assertion failed: $foo instanceof Bar (<- assert_handler())

Error: assert(): Assertion "$foo instanceof Bar" failed (<-
ASSERT_WARNING)

*Not executed*  (<- ASSERT_BAIL)

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

Reply via email to