Jump to content

What's the point of "isset"?


kreut

Recommended Posts

http://php.net/manual/en/types.comparisons.php

 

isset() is typically used to see if a variable was passed through a form, even if it was passed as empty.  But the second piece of code you've got checks if the value is "true" or not, which is defined according to some arcane rules listed in that table.

Thank you both for your responses.  To clarify, then, if I want to see if a particular form is sent in, I would check if that particular submit button "isset"; and if I want to see if a particular form item is not empty, I would then use if (!$variable_of_interest) --- would this be the standard way of checking these two form items?

More or less.  While I trust php's "isset" and it is useful for exactly what you describe, I don't trust php's "is true".  The big problem with it is that "0" is false.  But 0 is a perfectly good number, and it's most definitely "not empty", even though both !0 and empty(0) are TRUE!!  This quirk results in so many bugs, usually forms that mysteriously fail when particular input results in a 0 being tested for true-ness.

 

And the biggest gotcha with isset() is that false and 0 are "set" values, because "set" refers to the variable itself being set and not the value.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.