By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,347 Members | 1,390 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,347 IT Pros & Developers. It's quick & easy.

isser() and empty()

P: n/a
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
Aug 26 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.
js*******@attglobal.net
==================

Aug 26 '08 #2

P: n/a
Message-ID: <g8**********@registered.motzarella.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 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
http://slipperyhill.co.uk - http://4theweb.co.uk
Aug 26 '08 #3

P: n/a
Geoff Berrow wrote:
Message-ID: <g8**********@registered.motzarella.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.
js*******@attglobal.net
==================

Aug 26 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.