SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    453
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    least code to confirm false condition

    Whats a shorter way to code this?

    PHP Code:
    if (isset($tbl_key2) == FALSE) {



  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,035
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)
    Conditional logic is one of those things that looks simple enough but can present problems if you don't understand exactly what it's doing.

    if ("conditional statement evaluates to true"){ do_something(); }

    There are several "flavors" of "true" and "false".

    If you need to ensure an exact boolean false you need to use ===

    Variable and function returns can be "false" in different ways i.e. boolean false, empty string "", numeric 0

    The docs and experience debugging will be your better teacher, but for your example consider what isset() returns
    If a variable has been unset with unset(), it will no longer be set. isset() will return FALSE if testing a variable that has been set to NULL. Also note that a NULL byte ("\0") is not equivalent to the PHP NULL constant.
    So your asking
    if the expression "is $tbl_key2 equal to null?" then the if test is true.

    Depending on what your variable is and what your doing you may be able to simplify with a "not" - "!"

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    453
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks mitteneague for your great explanation. It has the answer I needed.

    Niche


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •