note 26926 added to function.error-reporting
| From: | sreid at sea-to-sky dot net | Date: | Mon, 18 Nov 2002 07:16:09 +0000 |
| Subject: | note 26926 added to function.error-reporting | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-39621@lists.php.net to get a copy of this message | ||
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);
--
http://www.php.net/manual/en/function.error-reporting.php
http://master.php.net/manage/user-notes.php?action=edit+26926
http://master.php.net/manage/user-notes.php?action=delete+26926
http://master.php.net/manage/user-notes.php?action=reject+26926