Re: Re: $_REQUEST problem

From: steve (UseLinkToEmail_at_dbForumz.com)
Date: 07/20/04


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


Relevant Pages

  • Re: Re: $_REQUEST problem
    ... > My approach to this is: always use isset() on any variable you ... Tight error reporting ensures that you ... explicit copying of var data ... Visit Topic URL to contact author (reg. ...
    (comp.lang.php)
  • Re: Re: $_REQUEST problem
    ... > My approach to this is: always use isset() on any variable you ... Tight error reporting ensures that you ... explicit copying of var data ... Visit Topic URL to contact author (reg. ...
    (comp.lang.php)
  • Re: Re: Is it ok to use error_reporting(0) to get rid of error m
    ... "undefined" warning from php. ... the warning reporting off. ... Visit Topic URL to contact author (reg. ...
    (comp.lang.php)
  • Elegant error reporting, possible?
    ... Is there a more elegant way of reporting line number besides putting ... Visit Topic URL to contact author (reg. ...
    (alt.php)