Doc #52338 [Com]: Handeling @ supressed errors in custom error handlers
| From: | chealer at gmail dot com | Date: | Mon, 16 Apr 2012 21:15:46 +0000 |
| Subject: | Doc #52338 [Com]: Handeling @ supressed errors in custom error handlers | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-8270@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=52338&edit=1
ID: 52338
Comment by: chealer at gmail dot com
Reported by: darren at powerssa dot com
Summary: Handeling @ supressed errors in custom error
handlers
Status: Closed
Type: Documentation Problem
Package: Documentation problem
Operating System: OSX
PHP Version: 5.3.2
Assigned To: degeberg
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2010-07-25 13:21:24] 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.
------------------------------------------------------------------------
[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 https://bugs.php.net/bug.php?id=52338&edit=1