I guess I missed the "last line" part, my bad.

Yes, you've got the idea for isset(). ! means NOT. So isset($id) will check
to see if $id is set, it doesn't care what the value is. !isset($id) will
see if $id is NOT set. A variable can be set and have an empty value, or be
false, null, etc.

The idea behind "undefined variable" is that you must assign a default value
to to the variable before you print it out or use it in a comparison. You
can adjust your error_reporting() so you don't get these errors, but it's
better to leave it on and make your code work. You can see they are just
warnings, and your code will still work. It's an easy way to find typo'd
variable names. Also, when register_globals is ON, you might use $id and
expect the value to be passed through the URL. By getting this warning when
you check $id, you should realize that the variable needs to be validated,
because it can be anything coming through the URL.

Hope that helps.

---John Holmes...

----- Original Message -----
From: "Jason Soza" <[EMAIL PROTECTED]>
Sent: Thursday, April 25, 2002 12:33 PM
Subject: Re: [PHP] Parse Error - Help? (AGAIN)

> Sorry for the length of the code, but I felt I described the problem,
> (parse error, last line) and if I hadn't posted the entire code I
> probably would've been asked to. This list can be a little confusing
> for a newbie: just a couple days ago I read someone saying "too much
> information is better than not enough" and now I'm getting that I
> posted too much. I'm still learning! :)
> What does the ! in if(!isset($id)) { $id = 0; } do? I think I get what
> this bit does in general: checks if $id has been assigned anything, if
> it's empty it gets assigned 0. Correct? Then I can use if($id)
> statements later on without having PHP return "Undefined Variable"
> errors. Right?
> Thanks for your help, I'll work on my PHP listetiquette.
> Jason Soza
> ----- Original Message -----
> From: "1LT John W. Holmes" <[EMAIL PROTECTED]>
> Date: Thursday, April 25, 2002 5:35 am
> Subject: Re: [PHP] Parse Error - Help? (AGAIN)
> > I don't have your original code (which, btw, you shoudn't ever
> > post that
> > much code without explicitly saying what the error was, what line
> > it was
> > one, highlighting that line, and saying what you've done so far),
> > but these
> > errors are caused by not giving a default value to a variable,
> > basically.
> > If you have something like this:
> >
> > if($id = 5)
> > {
> >  //whatever
> > }
> >
> > and $id hasn't been assigned a value, then you'll get that
> > warning. In
> > previous versions of PHP, you wouldn't get the warning, you'd just get
> > FALSE.
> >
> > So, before you test the value of a variable, or echo the value
> > out, make
> > sure you've assigned it something.
> >
> > if(!isset($id)) { $id = 0; }
> >
> > Hopefully that's not too confusing....it's hard to explain.
> >
> > ---John Holmes...
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to