Doc #52338 [Opn->Csd]: Handeling @ supressed errors in custom error handlers
| From: | degeberg@php.net | Date: | Sun, 25 Jul 2010 11:21:24 +0000 |
| Subject: | Doc #52338 [Opn->Csd]: Handeling @ supressed errors in custom error handlers | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-4733@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52338&edit=1
ID: 52338
Updated by: degeberg@php.net
Reported by: darren at powerssa dot com
Summary: Handeling @ supressed errors in custom error handlers
-Status: Open
+Status: Closed
Type: Documentation Problem
Package: Documentation problem
Operating System: OSX
PHP Version: 5.3.2
-Assigned To:
+Assigned To: degeberg
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2010-07-25 13:20:20] degeberg@php.net
Automatic comment from SVN on behalf of degeberg
Revision: http://svn.php.net/viewvc/?view=revision&revision=301531
Log: Improved example in set_error_handler(). Fixes PHP bug #52338.
------------------------------------------------------------------------
[2010-07-14 18:40:08] 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
}
?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52338&edit=1