473,386 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
Aug 26 '08 #1
3 1611
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Cyrus D. | last post by:
Hi guys, What's the best way to test for an empty form value ? I am doing it like this now: $test = $_POST; if(strlen($test) < 1) // it is empty ! Maybe I can just go:
13
by: Mikko Ohtamaa | last post by:
From XML specification: The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. (This means that <foo></foo> is equal to...
4
by: Ramiro Barbosa, Jr. | last post by:
All, In regards to the call below, I was wondering why is it that the 'szMessage' receiving buffer results in an empty one, but by printing 'ret' it indicates the number of bytes I am indeed...
12
by: Stefan Weiss | last post by:
Hi. (this is somewhat similar to yesterday's thread about empty links) I noticed that Tidy issues warnings whenever it encounters empty tags, and strips those tags if cleanup was requested....
2
by: Andreas Palm | last post by:
I have a dataset that has DBNull in certain columns, now when I write out this one to XML, I only get the columns as elements that do have data in it. However I do need also the empty colums as...
11
by: Dan Bass | last post by:
which one do you use and why? MyString == null || MyString == "" vs MyString == null || MyString.Length == 0
2
by: Bob Stearns | last post by:
I thought that the given expression was always TRUE if "not_there" wasn't among the keys (or subscripts if you will) of $_SESSION. Below find a dump of $_SESSION, a small snippet of code and the...
14
by: cj | last post by:
What is string.empty used for? I can't say: if string.empty then I have to use: if string = "" then which is ok, I just want to know what .empty is for.
26
by: anonieko | last post by:
In the past I always used "" everywhere for empty string in my code without a problem. Now, do you think I should use String.Empty instead of "" (at all times) ? Let me know your thoughts.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.