note 65560 added to function.is-null
| From: | smunksatyahoodotcom at osu1 dot php dot net | Date: | Wed, 03 May 2006 13:02:50 +0000 |
| Subject: | note 65560 added to function.is-null | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-110448@lists.php.net to get a copy of this message | ||
A follow up warning to jsjacobs at piercedmedia dot com's entry.
empty() is true even for variables set to 0.
<?php
print '$test = ""<br>';
$test = '';
if(empty($test))
print '$test is Empty<BR>';
else
print '$test is Not Empty<BR>';
if(empty($test) && $test != '0')
print '$test is Empty and != "0"<BR>';
else
print '$test is (Not Empty) OR ($test = "0")<BR>';
if(empty($test) && $test != 0)
print '$test is Empty and != 0<BR>';
else
print '$test is (Not Empty) OR ($test = 0)<BR>';
print '<br>$test = 0<br>';
$test = 0;
if(empty($test))
print '$test is Empty<BR>';
else
print '$test is Not Empty<BR>';
if(empty($test) && $test != '0')
print '$test is Empty and != "0"<BR>';
else
print '$test is (Not Empty) OR ($test = "0")<BR>';
if(empty($test) && $test != 0)
print '$test is Empty and != 0<BR>';
else
print '$test is (Not Empty) OR ($test = 0)<BR>';
?>
Generates:
$test = ""
$test is Empty
$test is Empty and != "0"
$test is (Not Empty) OR ($test = 0)
$test = 0
$test is Empty
$test is (Not Empty) OR ($test = "0")
$test is (Not Empty) OR ($test = 0)
Hence to determine if a variable is '' or 0 one must use:
if(empty($test) && $test != '0'), usefull when updating a mysql database field to
NULL.
read more at: http://se2.php.net/manual/en/function.empty.php
----
Server IP: 193.27.201.10 (proxied: 193.27.201.10 1.0 www1.shellkonto.se:3128 (squid/2.5.STABLE4))
Probable Submitter: 212.214.122.194
----
X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_MESSAGE autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.is-null.php
Edit -- http://master.php.net/note/edit/65560
Del: integrated -- http://master.php.net/note/delete/65560/integrated
Del: useless -- http://master.php.net/note/delete/65560/useless
Del: bad code -- http://master.php.net/note/delete/65560/bad+code
Del: spam -- http://master.php.net/note/delete/65560/spam
Del: non-english -- http://master.php.net/note/delete/65560/non-english
Del: in docs -- http://master.php.net/note/delete/65560/in+docs
Del: other reasons-- http://master.php.net/note/delete/65560
Reject -- http://master.php.net/note/reject/65560
Search -- http://master.php.net/manage/user-notes.php