note 29712 added to function.empty
| From: | lsole at maresme dot net | Date: | Sat, 22 Feb 2003 19:59:54 +0000 |
| Subject: | note 29712 added to function.empty | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44351@lists.php.net to get a copy of this message | ||
I do not use empty() nor isset() to check form input. When I want to know if some field has been
filled in, I simply check if $field!=''. My reasons are:
-empty() fails if the field has 0 (the zero value), which may be a value I need.
-isset() always returns true for a POST var, even if the form field was empty.
So instead of...
if (!empty($field)) {...} // bad
...or...
if (isset($field)) {...} // bad
...I use
if ($field != '') {...} // good!
As other comments here, I also believe empty() would be more use useful if it returned true for 0.
--
http://www.php.net/manual/en/function.empty.php
http://master.php.net/manage/user-notes.php?action=edit+29712
http://master.php.net/manage/user-notes.php?action=delete+29712
http://master.php.net/manage/user-notes.php?action=reject+29712