note 31710 added to function.empty
| From: | alef0 at freenet dot de | Date: | Thu, 01 May 2003 01:34:13 +0000 |
| Subject: | note 31710 added to function.empty | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-47313@lists.php.net to get a copy of this message | ||
I agree, that this function is not useful. There is a fundamental difference between an empty set
and the value 0.
I use the function def() for testing, wether a variable have a value or not:
function def ($var)
{
if ("$var" != "") { return(1); }
else { return(0); };
};
It is very important, to write '"$var" != ""', otherwise this function
will have the same behavior than empty()!
Of course, def() will not work with an array! When I know, that a variable is introduced as an
array, I simply use the function count.
Never I use a variable without initialisation. When I need a new array or some variable, I simply
type
$foo = "";
$foo_array = array();
Of course, there is a little risk in this and is_array() is a very useful function!
You can also define def() more general:
function def ($var)
{
if (is_array($var)) { return(count($var)); }
elseif ("$var" != "") { return(1); }
else { return(0); };
};
--
http://www.php.net/manual/en/function.empty.php
http://master.php.net/manage/user-notes.php?action=edit+31710
http://master.php.net/manage/user-notes.php?action=delete+31710
http://master.php.net/manage/user-notes.php?action=reject+31710