From:             gwarnants at gmail dot com
Operating system: Windows XP
PHP version:      5.4.7
Package:          *General Issues
Bug Type:         Bug
Bug description:restore_error_handler does not restore previous errors mask

Description:
------------
Dear PHP Team,

I don't know if it's a bug but I discovered a strange behavior :

When setting a custom error handler, we can choose an error mask as a 2nd
parameter to catch only some kinds of errors.
If I set 2 error handlers with differents masks, and trying to restore back
my first handler by calling restore_error_handler(), my first handler is
now running with the second error mask

Perhaps it is a normal behavior because set_error_handler() is setting a
"global" error mask, but if it is, I think there is no
way to know the previous error_mask to restore it properly (that value
isn't returned by error_reporting())

Regards,
Geoffray

Test script:
---------------
class CustomErrorHandler
{
    public static function handler($errrno, $errstr)
    {
        echo "HANDLING: $errstr\n";

        // i set an internal error_handler other catch WARNINGS ONLY
        set_error_handler(array('CustomErrorHandler', 'internal_handler'),
E_WARNING|E_USER_WARNING);
        fopen('file_not_found.dat', 'r');   // will trigger a E_WARNING
        restore_error_handler();    // doing this i think previous handler
will be restored to E_ALL... but it's not ??
    }

    private static function internal_handler($errrno, $errstr)
    {
        echo "  INTERNAL HANDLER: $errstr\n";
    }
}


set_error_handler(array('CustomErrorHandler', 'handler'), E_ALL);

trigger_error('User notice 1',  E_USER_NOTICE);
trigger_error('User warning 1', E_USER_WARNING);
trigger_error('User notice 2',  E_USER_NOTICE); // will not be caught !
trigger_error('User warning 2', E_USER_WARNING);

Expected result:
----------------
HANDLING: User notice 1
  INTERNAL HANDLER: fopen(file_not_found.dat): failed to open stream: No
such file or directory
HANDLING: User warning 1
  INTERNAL HANDLER: fopen(file_not_found.dat): failed to open stream: No
such file or directory
HANDLING: User notice 2
  INTERNAL HANDLER: fopen(file_not_found.dat): failed to open stream: No
such file or directory
HANDLING: User warning 2
  INTERNAL HANDLER: fopen(file_not_found.dat): failed to open stream: No
such file or directory

Actual result:
--------------
HANDLING: User notice 1
  INTERNAL HANDLER: fopen(file_not_found.dat): failed to open stream: No
such file or directory
HANDLING: User warning 1
  INTERNAL HANDLER: fopen(file_not_found.dat): failed to open stream: No
such file or directory


Notice:  User notice 2 in D:\wamp\www\custom_error_handler.php on line 29

HANDLING: User warning 2
  INTERNAL HANDLER: fopen(file_not_found.dat): failed to open stream: No
such file or directory

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

Reply via email to