Doc #52338 [NEW]: Handeling @ supressed errors in custom error handlers
| From: | darren at powerssa dot com | Date: | Wed, 14 Jul 2010 16:40:16 +0000 |
| Subject: | Doc #52338 [NEW]: Handeling @ supressed errors in custom error handlers | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-4687@lists.php.net to get a copy of this message | ||
From:
Operating system: OSX
PHP version: 5.3.2
Package: Documentation problem
Bug Type: Documentation Problem
Bug description:Handeling @ supressed errors in custom error handlers
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 bug report at http://bugs.php.net/bug.php?id=52338&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52338&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52338&r=trysnapshot53
Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52338&r=trysnapshottrunk
Fixed in SVN: http://bugs.php.net/fix.php?id=52338&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52338&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=52338&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=52338&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=52338&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=52338&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=52338&r=support
Expected behavior: http://bugs.php.net/fix.php?id=52338&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=52338&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=52338&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=52338&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52338&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=52338&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=52338&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=52338&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=52338&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=52338&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=52338&r=mysqlcfg