note 13254 deleted from function.isset by didou
| From: | didou@php.net | Date: | Sun, 18 May 2003 10:26:35 +0000 |
| Subject: | note 13254 deleted from function.isset by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-48506@lists.php.net to get a copy of this message | ||
Note Submitter: chris@owta.net
----
An example of how to and how not to check if form elements are empty:
<?
if ($HTTP_POST_VARS)
{
$a = $HTTP_POST_VARS['element'];
// Wrong
if (!$a)
{
echo "if(!\$a) true<br>";
}
// Right
if (!isset($a))
{
echo "if (!isset(\$a)) true<br>";
}
// Wrong
if (empty($a))
{
echo "if (empty(\$a)) true<br>";
}
echo "contents of 'element' field:".$a;
}
?>
-- In other words always use isset!
Try this out with a form and enter "0". Maybe it's blindingly obvious to most, but
caused me many a headache until i realised i should be using isset for strings, and not !$stringVar,
a feature which could be said to be a weakness of php, as it encourages bad practice.