Re: How to turn off warnings ???
| From: | Christian Reiniger | Date: | Wed, 25 Apr 2001 12:28:44 +0000 |
| Subject: | Re: How to turn off warnings ??? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-50284@lists.php.net to get a copy of this message | ||
On Wednesday 25 April 2001 13:28, ahmad varoqua wrote:
> Hello, I too am a novice and have the same problems with "warning:
> undefined variable" or "undefined index" when I have display errors
> 'on'. The scripts work fine and I have reg_globals 'off' (I've been
> following that thread closely as well!) . How critical are these
> warnings? Is it overenthusiam on php's error tracking? You say to
Well, "undefined variable" for example means, that at
if ($foobar == 0) {...}
$foobar hasn't been set to anything so far - it's value is undefined,
meaning that the if() can do what it wants.
> 'correct the code' and I believe you, but what should I do? I want my
Well, for example when working with URL parameters (which may or may not
be set), use some wrapper function to access them. I use this code:
/*
* Get global variable <name>
* Automatically strips slashes when needed
*/
function pbGetGlobal ($Name)
{
if (isset ($GLOBALS[$Name])) {
if (get_magic_quotes_gpc () &&
is_string ($GLOBALS[$Name]))
return stripslashes ($GLOBALS[$Name]);
else
return $GLOBALS[$Name];
}
else
{
return "";
}
}
$MyVar = pbGetGlobal ("foobar");
if ($MyVar == 0) {...}
--
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)
"Software is like sex: the best is for free" -- Linus Torvalds