Re: Re: $_REQUEST problem
From: steve (UseLinkToEmail_at_dbForumz.com)
Date: 07/20/04
- Next message: steve: "Re: Database size"
- Previous message: steve: "Re: Re: $_REQUEST problem"
- In reply to: Gordon Burditt: "Re: $_REQUEST problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 20 Jul 2004 05:06:01 -0000
"Gordon Burditt37" wrote:
> >This line of code make an "Undefined index" error on my PC,
> however it is
> >okay on my friend’s PC.
> >Anyone has this experience?
> >
> >
> >$somevar = $_REQUEST["name"];
>
> My approach to this is: always use isset() on any variable you
> aren’t absolutely sure is set before trying to use its value.
> You
> can NEVER be sure that a particular variable in $_GET, $_POST,
> $_REQUEST, $_COOKIE, $_SERVER, or $_SESSION is set at the start of
> execution of your page. Consider any "undefined index" or
"undefined
> variable" message to be a bug in your code.
>
> Also, use error_reporting(E_ALL) to make sure that if you use
> an uninitialized value, it gets reported.
>
> Gordon L. Burditt</font>
I second Gordon’s comment. Tight error reporting ensures that you
catch some very pesky bugs- more work, more reward.
If undefined is a valid value for any variable--in other works you
don’t want to get any warnings, then use this function around your
variable.
$somevar = nullit($_REQUEST["name"]);
Function nullit(&$varin) { //must pass by reference, so there is no
explicit copying of var data
//if undefined variable, then returns ’’ without doing an error,
otherwise just returns the var.
//this is done so we don’t get warning
if (isset($varin)) {
return ($varin);
}
else {
return (’’);
}
}
-- http://www.dbForumz.com/ This article was posted by author's request Articles individually checked for conformance to usenet standards Topic URL: http://www.dbForumz.com/PHP-_REQUEST-problem-ftopict131132.html Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=437578
- Next message: steve: "Re: Database size"
- Previous message: steve: "Re: Re: $_REQUEST problem"
- In reply to: Gordon Burditt: "Re: $_REQUEST problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|