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?
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
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
Derick Rethans wrote:
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.
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
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
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
Derick Rethans wrote:
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.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
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.
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.
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
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
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.)
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--
--
Graham Christensen
www.itrebal.com
www.iamgraham.net
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...
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
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...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--
--
Graham Christensen
www.itrebal.com
www.iamgraham.net
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.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...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--
--
Graham Christensen
www.itrebal.com
www.iamgraham.net
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
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:
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
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