note 26926 deleted from function.error-reporting by bjori
| From: | bjori@php.net | Date: | Mon, 24 Apr 2006 15:32:36 +0000 |
| Subject: | note 26926 deleted from function.error-reporting by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-109467@lists.php.net to get a copy of this message | ||
Note Submitter: sreid at sea-to-sky dot net
----
It seems that using E_NOTICE (included with E_ALL) is the only way to get warnings about undefined
variables. For example, if you type $soemthing when you mean $something, you may not get any message
about it unless you use E_NOTICE level reporting.
The problem is, at that level of reporting you also get notices about array indexes that have not
been set. This means lots of warnings when using $_GET['formvariable'] and such. You can
check isset($_GET['formvariable']) first, but that gets annoying, especially when it is
redundant to stricter input validation you need to do anyway.
The only solution I have found is to use set_error_handler() to register a custom error reporting
function to report everything except where the error string starts with "Undefined
index:". Then I call error_reporting(E_ALL). This seems to be the best compromise.
function error_handler($errno, $errstr, $errfile, $errline, $errctx) {
if ($errno == E_NOTICE && substr($errstr, 0, 17) == "Undefined index: ") return;
echo "\nerror_handler:\n\terrno=$errno\n\terrstr=$errstr\n";
echo "\terrfile=$errfile\n\terrline=$errline\n";
if ($errno & (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR)) die();
}
set_error_handler("error_handler");
error_reporting(E_ALL);