note 31709 deleted from function.empty by sniper

From: Date: Sat, 23 Aug 2003 00:16:53 +0000
Subject: note 31709 deleted from function.empty by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-54905@lists.php.net to get a copy of this message
Note Submitter: alef0@freenet.de ---- 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 an 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! If I know, that a variable is defined as an array, I simply use the function count. I'll never use a variable without initialisation. If 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); }; };

« previous php.notes (#54905) next »