# Inconsistency of empty() and isset() ?

- Thread: https://externals.io/message/22792
- Original archive: https://news-web.php.net/php.internals/22792
- Started by itrebal@gmail.com on 2006-04-15T14:52:05+00:00
- Messages: 17
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #22792 — itrebal@gmail.com — 2006-04-15T14:52:05+00:00

URL: https://externals.io/message/22792#22792

The following is a direct excerpt from the PHP manual on empty, and isset:
bool *empty* ( mixed var )
bool *isset* ( mixed var [, mixed var [, ...]] )
Is there a reason empty does not allow multiple variables at a time, as
isset? Was there thought behind it, or is it just an inconsistency?

---

## #22797 — itrebal@gmail.com — 2006-04-16T17:38:59+00:00

URL: https://externals.io/message/22792#22797 · In reply to: #22792

Regardless of if its an inconsistency, I created a patch for it. Here are
the files:
http://repository.itrebal.com/php/patches/empty/empty.php (Test file)
http://repository.itrebal.com/php/patches/empty/patch
-------------------------------
Graham Christensen
www.itrebal.com
www.iamgraham.net

---

## #22798 — Derick Rethans — 2006-04-16T21:40:32+00:00

URL: https://externals.io/message/22792#22798 · In reply to: #22792

> The following is a direct excerpt from the PHP manual on empty, and isset:
> bool *empty* ( mixed var )
> bool *isset* ( mixed var [, mixed var [, ...]] )
> Is there a reason empty does not allow multiple variables at a time, as
> isset? Was there thought behind it, or is it just an inconsistency?

There is a thought about it, and that is that we could not decide 
whether it should be an AND or an OR test between the different 
parameters.

Derick

---

## #22799 — Lukas Smith — 2006-04-16T22:54:22+00:00

URL: https://externals.io/message/22792#22799 · In reply to: #22798

Derick Rethans wrote:
> 
> 
> > […]
> 
> There is a thought about it, and that is that we could not decide 
> whether it should be an AND or an OR test between the different 
> parameters.

well it seems to be AND for isset() .. which is probably its closest 
"sibiling" .. so the obvious call when going for consistency would be to 
  AND in empty() as well ..

regards,
Lukas

---

## #22801 — Richard Lynch — 2006-04-16T23:24:11+00:00

URL: https://externals.io/message/22792#22801 · In reply to: #22798

> 
> There is a thought about it, and that is that we could not decide
> whether it should be an AND or an OR test between the different
> parameters.

I'm curious to know whoulda thunk it would be OR, and why?...

I mean, the most common usage I've seen, bar far, is for form input
validation of a zillion inputs.

I've never quite grokked why others think empty is "better" than isset
for that, and don't really want to even get into that thread (again)
here, but I am interested to know when you'd have a whole BUNCH of
args to test with empty and would want OR on a regular frequent basis.

-- 
Like Music?
http://l-i-e.com/artists.htm

---

## #22802 — Etienne Kneuss — 2006-04-16T23:25:55+00:00

URL: https://externals.io/message/22792#22802 · In reply to: #22799

As empty is "quite" the contrary of isset, the OR would be preferable
over AND.

Indeed:

if(!empty($var1) && !empty($var2))

could be simplified to

if(!empty($var1, $var2))

Regards.

-- 
Etienne Kneuss

http://www.colder.ch/
colder@php.net

---

## #22803 — Pierre — 2006-04-16T23:26:49+00:00

URL: https://externals.io/message/22792#22803 · In reply to: #22799

> Derick Rethans wrote:
> > […]
>
> well it seems to be AND for isset() .. which is probably its closest
> "sibiling" .. so the obvious call when going for consistency would be to
>   AND in empty() as well ..

Indeed, especially as everyone will tell you that isset and empty are
equivalent.

--Pierre

---

## #22804 — Brian Moon — 2006-04-17T00:01:28+00:00

URL: https://externals.io/message/22792#22804 · In reply to: #22803

> Indeed, especially as everyone will tell you that isset and empty are
> equivalent.


Are you saying that people misunderstand that or that you believe that 
to be true?  I see that misunderstanding a lot.  I have to educate 
people on that.  They don't seem to grok the subtle, yet crucial (and I 
believe, wonderful) difference between the two.

Brian.

---

## #22806 — Pierre — 2006-04-17T00:38:41+00:00

URL: https://externals.io/message/22792#22806 · In reply to: #22804

> > […]
>
>
> Are you saying that people misunderstand that or that you believe that
> to be true?  I see that misunderstanding a lot.  I have to educate
> people on that.  They don't seem to grok the subtle, yet crucial (and I
> believe, wonderful) difference between the two.

I was not clear :)

isset and empty share the same implementation, the only difference is
what they return (in short). They behave "the same", they should
continue do so if empty accept many arguments.

But this discussion just hence Derick's point, it is not that obvious
to bring consistency between the two functions.

--Pierre

---

## #22807 — itrebal@gmail.com — 2006-04-17T01:08:48+00:00

URL: https://externals.io/message/22792#22807 · In reply to: #22792

When I'm validating form data, there are many occasions (more than
not) that I require most of them to be completed, and not left blank.
In which case you would do:
if(empty($_GET['var1'], $_GET['var2'], $_GET['var3'])){
     //Display error, yadda yadda
}
as aposed to
if(empty($_GET['var1']) || empty($_GET['var2']) || empty($_GET['var3'])){
     //Display error, yadda yadda
}
which is a much cleaner and simpler method. Doing it the other way (AND/OR)
 doesn't seem to have many applications that I can see.


>
> The following is a direct excerpt from the PHP manual on empty, and isset:
> bool *empty* ( mixed var )
> bool *isset* ( mixed var [, mixed var [, ...]] )
> Is there a reason empty does not allow multiple variables at a time, as
> isset? Was there thought behind it, or is it just an inconsistency?
>



--
------------------------------------
Graham Christensen
www.itrebal.com
www.iamgraham.net

---

## #22810 — Richard Lynch — 2006-04-17T02:20:44+00:00

URL: https://externals.io/message/22792#22810 · In reply to: #22802

> As empty is "quite" the contrary of isset, the OR would be preferable
> over AND.

Sorry, folks!

I meant the other way 'round...

Whatever it is you check with a zillion form inputs, that's what you'd
want.

When would you need it the other way with a lot of inputs?

-- 
Like Music?
http://l-i-e.com/artists.htm

---

## #22812 — Richard Lynch — 2006-04-17T02:29:08+00:00

URL: https://externals.io/message/22792#22812 · In reply to: #22806

> isset and empty share the same implementation, the only difference is
> what they return (in short). They behave "the same", they should
> continue do so if empty accept many arguments.

Actually...

Unless the docs are lying to me...

empty() checks the contents of the value, and does something quite
different based on the value found.

isset() just plain checks in the hash table[s] if the variable has
been assigned, and that's it.

Plus, the meaning of empty() changed in some a way with "0" between
versions 3 and 4, and then again with respect to objects with no
properties between 4 and 5.

isset() has never changed its meaning out from under me. :-)

So, while the guts of the function may be the same in source, there's
got to be some kind of flag or something going on for empty() to be
checking all those values, no???

-- 
Like Music?
http://l-i-e.com/artists.htm

---

## #22815 — itrebal@gmail.com — 2006-04-17T02:38:20+00:00

URL: https://externals.io/message/22792#22815 · In reply to: #22812

What it comes down to, is it runs the exact same code on the variables,
I just changed the method of which they were called (ie: allowed multiple.)


>
> 
> > […]
>
> Actually...
>
> Unless the docs are lying to me...
>
> empty() checks the contents of the value, and does something quite
> different based on the value found.
>
> isset() just plain checks in the hash table[s] if the variable has
> been assigned, and that's it.
>
> Plus, the meaning of empty() changed in some a way with "0" between
> versions 3 and 4, and then again with respect to objects with no
> properties between 4 and 5.
>
> isset() has never changed its meaning out from under me. :-)
>
> So, while the guts of the function may be the same in source, there's
> got to be some kind of flag or something going on for empty() to be
> checking all those values, no???
>
> --
> Like Music?
> http://l-i-e.com/artists.htm
>
> --
> 
> 
>
>


--
------------------------------------
Graham Christensen
www.itrebal.com
www.iamgraham.net

---

## #22819 — Ron Korving — 2006-04-17T12:53:30+00:00

URL: https://externals.io/message/22792#22819 · In reply to: #22812

isset() does more than check the existance in a hash table, because this the
following is true:

$foo = null;
isset($foo);  // returns false, even though $foo is initialized
echo $foo;    // will not cause a NOTICE, because $foo is initialized

- Ron


""Richard Lynch"" <ceo@l-i-e.com> wrote in message
news:3516.209.254.223.2.1145240948.squirrel@www.l-i-e.com...
> 
> > […]
>
> Actually...
>
> Unless the docs are lying to me...
>
> empty() checks the contents of the value, and does something quite
> different based on the value found.
>
> isset() just plain checks in the hash table[s] if the variable has
> been assigned, and that's it.
>
> Plus, the meaning of empty() changed in some a way with "0" between
> versions 3 and 4, and then again with respect to objects with no
> properties between 4 and 5.
>
> isset() has never changed its meaning out from under me. :-)
>
> So, while the guts of the function may be the same in source, there's
> got to be some kind of flag or something going on for empty() to be
> checking all those values, no???
>
> -- 
> Like Music?
> http://l-i-e.com/artists.htm

---

## #22820 — itrebal@gmail.com — 2006-04-17T17:46:37+00:00

URL: https://externals.io/message/22792#22820 · In reply to: #22819

Should I go ahead and submit this patch? Where should I go about doing so? I
looked around bugs.php.net but am unsure.


>
> isset() does more than check the existance in a hash table, because this
> the
> following is true:
>
> $foo = null;
> isset($foo);  // returns false, even though $foo is initialized
> echo $foo;    // will not cause a NOTICE, because $foo is initialized
>
> - Ron
>
>
> ""Richard Lynch"" <ceo@l-i-e.com> wrote in message
> news:3516.209.254.223.2.1145240948.squirrel@www.l-i-e.com...
> > […]
>
> --
> 
> 
>
>


--
------------------------------------
Graham Christensen
www.itrebal.com
www.iamgraham.net

---

## #22821 — Andi Gutmans — 2006-04-18T00:25:40+00:00

URL: https://externals.io/message/22792#22821 · In reply to: #22801

We had a huge thread about this a while back (1-2 years) where this 
was discussed in great depth. The agreement was that for isset() it's 
very straight forward and usefull and that the semantics with empty() 
would be confusing and problematic, and therefore, the decision was 
to just support this for isset(). For the full reasoning I suggest to 
search the archives. Shouldn't take too long to find.

Andi

At 04:24 PM 4/16/2006, Richard Lynch wrote:
>
> > […]
>
>I'm curious to know whoulda thunk it would be OR, and why?...
>
>I mean, the most common usage I've seen, bar far, is for form input
>validation of a zillion inputs.
>
>I've never quite grokked why others think empty is "better" than isset
>for that, and don't really want to even get into that thread (again)
>here, but I am interested to know when you'd have a whole BUNCH of
>args to test with empty and would want OR on a regular frequent basis.
>
>--
>Like Music?
>http://l-i-e.com/artists.htm

---

## #22822 — Andi Gutmans — 2006-04-18T00:26:42+00:00

URL: https://externals.io/message/22792#22822 · In reply to: #22820

Nope you shouldn't, as per my previous email.

At 10:46 AM 4/17/2006, itrebal@gmail.com wrote:
>Should I go ahead and submit this patch? Where should I go about doing so? I
>looked around bugs.php.net but am unsure.
>
>
> > […]
>
>
>--
>------------------------------------
>Graham Christensen
>www.itrebal.com
>www.iamgraham.net
