Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.