#46374 [Opn]: Error-control operator does not suppress "undefined index" in set_error_handler

From: Date: Sat, 25 Oct 2008 15:07:53 +0000
Subject: #46374 [Opn]: 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-1244@lists.php.net to get a copy of this message
ID: 46374 User updated by: phpbugs at sevenlight dot com Reported By: phpbugs at sevenlight dot com Status: Open Bug Type: Documentation problem Operating System: * PHP Version: 5.2.6 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#1244) next »