#46374 [Opn->Bgs]: Error-control operator does not suppress "undefined index" in set_error_handler
| From: | felipe@php.net | Date: | Sun, 26 Oct 2008 16:31:34 +0000 |
| Subject: | #46374 [Opn->Bgs]: Error-control operator does not suppress "undefined index" in set_error_handler | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-1253@lists.php.net to get a copy of this message | ||
ID: 46374
Updated by: felipe@php.net
Reported By: phpbugs at sevenlight dot com
-Status: Open
+Status: Bogus
Bug Type: Documentation problem
Operating System: *
PHP Version: 5.2.6
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Says the documentation:
"error_reporting() settings will have no effect and your error handler
will be called regardless - however you are still able to read the
current value of error_reporting and act appropriately. Of particular
note is that this value will be 0 if the statement that caused the error
was prepended by the @ error-control operator."
I.e.
<?php
function ErrorHandler() {
var_dump(error_reporting()); // 0
}
set_error_handler('ErrorHandler');
echo @$a[1];
Previous Comments:
------------------------------------------------------------------------
[2008-10-25 15:07:53] phpbugs at sevenlight dot com
The issue is that, according to the documentation, the value of the
first parameter ($iErr) in my example "will be 0 if the statement that
caused the error was prepended by the @ error-control operator."
The undefined index error was pre-pended by the @ error-control
operator. I understand that this will still call my error handler
callback, but it should have set the value of $iErr to 0.
------------------------------------------------------------------------
[2008-10-25 12:29:19] kalle@php.net
Correct me if I'm wrong, but this doesn't looks like an documentation
issue. Its probably your error reporting thats set to E_ALL, and not
E_ALL & ~E_NOTICE so notices will be generated.
You can set the optional second parameter on set_error_handler to
ignore notices, eg.:
set_error_reporting('ErrorHandler', E_ALL & ~E_NOTICE);
------------------------------------------------------------------------
[2008-10-24 05:21:39] phpbugs at sevenlight dot com
Description:
------------
A set_error_handler() callback is receiving an error code of 8
(E_NOTICE) for an undefined index, even though it has been suppressed by
the @ operator. As per the documentation, the value of the error should
be 0.
Tested on 5.2 and 5.3.
This is potentially just a documentation problem?
I find that the error code could be useful even if it has been
suppressed, therefore suggesting that an extra variable being passed to
the callback notifying it whether or not the @ operator was used or not
would be more useful.
Reproduce code:
---------------
<?php
function ErrorHandler($iErr, $sError)
{
if ($iErr) {
die('This should not happen (' . $iErr . '). Error should have
been suppressed: ' . $sError);
} else {
die('Error suppressed.');
}
}
set_error_handler('ErrorHandler');
$a = array();
echo @$a[ 'suppress-me' ];
?>
Expected result:
----------------
Error suppressed.
Actual result:
--------------
This should not happen (8). Error should have been suppressed:
Undefined index: suppress-me
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46374&edit=1