note 29712 deleted from function.empty by didou

From: Date: Wed, 10 Sep 2003 10:47:04 +0000
Subject: note 29712 deleted from function.empty by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-55927@lists.php.net to get a copy of this message
Note Submitter: lsole@maresme.net ---- [[[Editors note: It depends on what a person wants and it's not uncommon for someone to want '0' to be seen as empty. In PHP3, the string '0' was not considered empty. Anyway, doing $foo == '' is an option but it will shout an E_NOTICE level error if $foo is not set. strlen() would also provide this E_NOTICE error, as would if($foo).]]] 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.

« previous php.notes (#55927) next »