note 100584 added to function.empty
| From: | rodolphe dot bodeau at free dot fr | Date: | Mon, 25 Oct 2010 13:37:24 +0000 |
| Subject: | note 100584 added to function.empty | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173434@lists.php.net to get a copy of this message | ||
Be careful, if "0" (zero as a string), 0 (zero as an integer) and -0 (minus zero as an
integer) return true, "-0" (minus zero as a string (yes, I already had some customers that
wrote -0 into a form field)) returns false. You need to cast your variable before testing it with
the empty() function :
<?php
$var = "-0";
echo empty($var); // returns false
$var = (int) $var; // casts $var as an integer
echo empty($vat); // returns true
?>
----
Server IP: 195.221.21.36
Probable Submitter: 82.228.65.50
----
Manual Page -- http://www.php.net/manual/en/function.empty.php
Edit -- https://master.php.net/note/edit/100584
Del: integrated -- https://master.php.net/note/delete/100584/integrated
Del: useless -- https://master.php.net/note/delete/100584/useless
Del: bad code -- https://master.php.net/note/delete/100584/bad+code
Del: spam -- https://master.php.net/note/delete/100584/spam
Del: non-english -- https://master.php.net/note/delete/100584/non-english
Del: in docs -- https://master.php.net/note/delete/100584/in+docs
Del: other reasons-- https://master.php.net/note/delete/100584
Reject -- https://master.php.net/note/reject/100584
Search -- https://master.php.net/manage/user-notes.php