php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #46374 Error-control operator does not suppress "undefined index" in set_error_handler
Submitted: 2008-10-24 05:21 UTC Modified: 2008-10-26 16:31 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: phpbugs at sevenlight dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5.2.6 OS: *
Private report: No CVE-ID: None
 [2008-10-24 05:21 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-25 12:29 UTC] 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-25 15:07 UTC] 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-26 16:31 UTC] felipe@php.net
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];

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Dec 04 20:00:01 2025 UTC