note 62442 added to function.empty
| From: | nobody at example dot com | Date: | Tue, 28 Feb 2006 20:06:53 +0000 |
| Subject: | note 62442 added to function.empty | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-104575@lists.php.net to get a copy of this message | ||
Re: inerte is my gmail.com username's comment:
While that may be true, those two statements (empty($var), $var == '') are NOT the same.
When programming for web interfaces, where a user may be submitting '0' as a valid field
value, you should not be using empty().
<?php
$str = '0';
// outputs 'empty'
echo empty($str) ? 'empty' : 'not empty';
// outputs 'not empty'
echo $str == '' ? 'empty' : 'not empty';
?>
----
Server IP: 216.235.15.211
Probable Submitter: 68.148.210.62
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.empty.php
Edit -- http://master.php.net/note/edit/62442
Del: integrated -- http://master.php.net/note/delete/62442/integrated
Del: useless -- http://master.php.net/note/delete/62442/useless
Del: bad code -- http://master.php.net/note/delete/62442/bad+code
Del: spam -- http://master.php.net/note/delete/62442/spam
Del: non-english -- http://master.php.net/note/delete/62442/non-english
Del: in docs -- http://master.php.net/note/delete/62442/in+docs
Del: other reasons-- http://master.php.net/note/delete/62442
Reject -- http://master.php.net/note/reject/62442
Search -- http://master.php.net/manage/user-notes.php