note 31710 deleted from function.empty by alindeman
| From: | alindeman@php.net | Date: | Thu, 01 May 2003 01:35:54 +0000 |
| Subject: | note 31710 deleted from function.empty by alindeman | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-47314@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); };
};