isser() and empty()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Twayne

    isser() and empty()

    This post is really prompted by the "shortcut for isset()?" thread and
    many others similar to it:

    In the case of POST/GET etc, isn't it a lot better to use If(empty($var)
    instead of Isset? Isset will return true if there's so much as an empty
    string there, where empty() would declare it to be False.
    Isset is great for radio buttons, things along those lines, but not
    if you want to be sure a name, address, etc. at least has been entered
    in it.

    But interestingly enough, I never see anyone do it that way; isset() is
    always used, it seems.

    Or am I missing something basic? I know I'm a neophyte, but ... empty()
    just feels like a lot better choice than isset() in most forms, No?

    TIA

    Twayne


  • Jerry Stuckle

    #2
    Re: isser() and empty()

    Twayne wrote:
    This post is really prompted by the "shortcut for isset()?" thread and
    many others similar to it:
    >
    In the case of POST/GET etc, isn't it a lot better to use If(empty($var)
    instead of Isset? Isset will return true if there's so much as an empty
    string there, where empty() would declare it to be False.
    Isset is great for radio buttons, things along those lines, but not
    if you want to be sure a name, address, etc. at least has been entered
    in it.
    >
    But interestingly enough, I never see anyone do it that way; isset() is
    always used, it seems.
    >
    Or am I missing something basic? I know I'm a neophyte, but ... empty()
    just feels like a lot better choice than isset() in most forms, No?
    >
    TIA
    >
    Twayne
    >
    >
    >
    No, isset() tells you if the field is set. A null string ('') is not
    the same as a field not being set.

    When checking $_POST or $_GET, I want to know if it's set or not. I'll
    worry about validating the data later.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Geoff Berrow

      #3
      Re: isser() and empty()

      Message-ID: <g8vhkl$m8m$1@r egistered.motza rella.orgfrom Jerry Stuckle
      contained the following:
      >
      >When checking $_POST or $_GET, I want to know if it's set or not. I'll
      >worry about validating the data later.
      I'd have thought that once you had checked the form has been POSTed
      there isn't an awful lot of point in checking if, say, $_POST['surname']
      is set. Assuming empty() is part of the validation, you may as well let
      it do both jobs.
      --
      Geoff Berrow 011000100110110 0010000000110
      001101101011011 001000110111101 100111001011
      100110001101101 111001011100111 010101101011
      http://slipperyhill.co.uk - http://4theweb.co.uk

      Comment

      • Jerry Stuckle

        #4
        Re: isser() and empty()

        Geoff Berrow wrote:
        Message-ID: <g8vhkl$m8m$1@r egistered.motza rella.orgfrom Jerry Stuckle
        contained the following:
        >
        >When checking $_POST or $_GET, I want to know if it's set or not. I'll
        >worry about validating the data later.
        >
        I'd have thought that once you had checked the form has been POSTed
        there isn't an awful lot of point in checking if, say, $_POST['surname']
        is set. Assuming empty() is part of the validation, you may as well let
        it do both jobs.
        But assuming empty() is part of the validation is not a valid
        assumption. There may be perfectly good reasons for a value to be set
        to a null string - or 0 or even an array of checkboxes with none checked.

        Checking to see if the variable is set or not is part of the display
        logic. Whether an empty value is valid or not is part of the business
        logic. It helps to keep the two separate.

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        Working...