Edit report at https://bugs.php.net/bug.php?id=63206&edit=1
ID: 63206
User updated by: gwarnants at gmail dot com
Reported by: gwarnants at gmail dot com
Summary: restore_error_handler does not restore previous
errors mask
Status: Open
Type: Bug
Package: *General Issues
Operating System: Windows XP
PHP Version: 5.4.7
Block user comment: N
Private report: N
New Comment:
Same problem in 5.3.4 on Windows
Previous Comments:
------------------------------------------------------------------------
[2013-01-02 14:14:41] joe dot bowman at edigitalresearch dot com
Same problem in 5.4.8 on CentOS 6.3.
------------------------------------------------------------------------
[2012-11-15 08:57:23] gwarnants at gmail dot com
Here is a simpler example to illustrate the problem. As you see, the 2nd
trigger_error will not be caught because the error reporting isn't restored to
its initial state.
set_error_handler('handler1', E_ALL);
trigger_error('notice 1', E_USER_NOTICE); // OK
trigger_error('notice 2', E_USER_NOTICE); // not caught !
function handler1($errrno, $errstr)
{
echo "HANDLER1 : $errstr\n";
set_error_handler('handler2', E_USER_WARNING);
restore_error_handler();
}
function handler2($errrno, $errstr)
{
}
------------------------------------------------------------------------
[2012-10-17 04:57:25] gwarnants at gmail dot com
Any feedback ?
------------------------------------------------------------------------
[2012-10-03 09:59:45] gwarnants at gmail dot com
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 this bug report at https://bugs.php.net/bug.php?id=63206&edit=1