#19056 [Com]: empty() function is completely broken
| From: | adets at idsk dot com | Date: | Fri, 23 Aug 2002 16:23:06 +0000 |
| Subject: | #19056 [Com]: empty() function is completely broken | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-17673@lists.php.net to get a copy of this message | ||
ID: 19056
Comment by: adets@idsk.com
Reported By: adets@idsk.com
Status: Bogus
Bug Type: Unknown/Other Function
Operating System: Linux
PHP Version: 4.2.2
New Comment:
Yes, breaking of compatibility is a very bad thing.
But may be at least for PHP-5 it can be possible to change
empty() behaviour to not return true for "0" _string_?
Seems that PHP can distinguish data types... Such change
can make code much more clean...
Ok, let it be a feature request from an old PHP user ;-)
Previous Comments:
------------------------------------------------------------------------
[2002-08-22 16:12:54] rasmus@php.net
Well, it has always been documented to work like this and it isn't
going to change as it would break countless applications. And it is
only "useless" for fields where "0" is valid input. For those use
isset()&&strlen(). Basically empty() works the same as just doing
if($var) and if("0") is still false, so any other behaviour would be
inconsistent.
------------------------------------------------------------------------
[2002-08-22 16:08:29] adets@idsk.com
I don't want to check that is is set (we have isset()
fucntion as you noted before), I want to check that it is
_not_ empty.
If you'll look in the user comments to the empty() function
than you'll find that this is a very common problem -
usually it has no sence to check that smth. is _not_ zero
(because it is more easy to compare it with zero), the task
is to check that it is _not_ _empty_, for example, if
somebody submits a form it makes a real difference - ""
string (_empty_, user passed empty field) and "0" string
(that _has_ a value).
Now people are using additional checks just because of the
fact that empty() function is not working where it should.
------------------------------------------------------------------------
[2002-08-22 15:52:18] rasmus@php.net
The example in the documentation shows clearly that empty() returns
true when a var is not set or when it is set to something that
evaluates to 0. If you only want to check whether something is set,
use the isset() function.
------------------------------------------------------------------------
[2002-08-22 15:47:04] adets@idsk.com
empty() function is not working correctly.
It returns true if variable has a value of: 0 & 0.0
(integer, float), false (boolean) or "0" (string).
This makes this function COMPLETELY USELESS.
Is it possible to implement this function correctly (it
will be great!!!), remove it at
all (because it is useless now) or at least correct
documentation?
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=19056&edit=1