note 64580 deleted from function.empty by didou
| From: | didou@php.net | Date: | Sun, 18 May 2008 00:57:45 +0000 |
| Subject: | note 64580 deleted from function.empty by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-139482@lists.php.net to get a copy of this message | ||
Note Submitter: ben at wbtproductions dot com
----
It is important to note that empty() does not check data type. This can change the functioning of
any program if, at some point, your data might be all zeroes, containing no real data, but also not
empty by PHP's definition.
Think about this:
$data = "00000";
if (empty($data))
echo "The data appears empty.";
if (0==$data) //Use this test for number applications!!
echo "The data is zero.";
$data = 0;
if (empty($data))
echo "Remember, zero is empty.";
outputs:
The data is zero.
Remember, zero is empty.
This could crop up in ZIP codes and phone numbers or zero-filled/zero-padded values from SQL. Watch
those variable types!