php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #52338 Handeling @ supressed errors in custom error handlers
Submitted: 2010-07-14 18:40 UTC Modified: 2010-07-25 13:21 UTC
From: darren at powerssa dot com Assigned: degeberg (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.3.2 OS: OSX
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: darren at powerssa dot com
New email:
PHP Version: OS:

 

 [2010-07-14 18:40 UTC] darren at powerssa dot com
Description:
------------
The error suppression docs do not describe how the @ suppression affects custom error functions and that the error will still be passed to custom error handlers regardless of the @ suppression.

As per my comment below it would be useful to have an example of how to check for suppressed errors in a custom error hanler.

After some time investigating as to why I was still getting errors that were supposed to be suppressed with @ I found the following.

1. If you have set your own default error handler then the error still gets sent to the error handler regardless of the @ sign.

2. As mentioned below the @ suppression only changes the error level for that call. This is not to say that in your error handler you can check the given $errno for a value of 0 as the $errno will still refer to the TYPE(not the error level) of error e.g. E_WARNING or E_ERROR etc

3. The @ only changes the rumtime error reporting level just for that one call to 0. This means inside your custom error handler you can check the current runtime error_reporting level using error_reporting() (note that one must NOT pass any parameter to this function if you want to get the current value) and if its zero then you know that it has been suppressed.
<?php
// Custom error handler
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
    if ( 0 == error_reporting () ) {
        // Error reporting is currently turned off or suppressed with @
        return;
    }
    // Do your normal custom error reporting here
}
?>

For more info on setting a custom error handler see: http://php.net/manual/en/function.set-error-handler.php
For more info on error_reporting see: http://www.php.net/manual/en/function.error-reporting.php


Test script:
---------------
<?php
// Custom error handler
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
    if ( 0 == error_reporting () ) {
        // Error reporting is currently turned off or suppressed with @
        return;
    }
    // Do your normal custom error reporting here
}
?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-25 13:20 UTC] degeberg@php.net
Automatic comment from SVN on behalf of degeberg
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=301531
Log: Improved example in set_error_handler(). Fixes PHP bug #52338.
 [2010-07-25 13:21 UTC] degeberg@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: degeberg
 [2010-07-25 13:21 UTC] degeberg@php.net
Thank you for your report. I've improved the example to check if the $errno is included in the error_reporting setting. It should show up in the manual within a week.
 [2012-04-16 21:15 UTC] chealer at gmail dot com
This was more properly fixed by rasmus with http://svn.php.net/viewvc/phpdoc/en/trunk/language/operators.xml?r1=322134&r2=323370

See also #61747.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 13:00:02 2026 UTC