> if ($lastname="") {
>     $insert="no"
> }

Even though you should use either empty() or isset(), you'd have a parse error if you 
wrote that as:
if (""=$lastname) {
   $insert="no"
}

It takes a little time to learn to write the test 'backwards' but if you do the php 
parser will help and catch your single = typo when you really wanted a compare ==.  I 
call that defensive programming.  

Another thing I do in my defensive programming tool kit is to use fuzzy compares to 
trap errors. For instance, say you're writing an application to maintain a price list 
for products, and are validating that the price.  You could write the validation to 
check for == 0, and output an error in that case.  But it's more defensive to check 
for <= 0, that way if data gets corrupted somehow, you'll find out about it sooner 
rather than later.  

I also write my applications to validate the data on retrieval from the database, as 
well as when the user to requesting update.  If you do that, any corruption of the 
data will be seen by the user even when inquiring on items. So again problems are 
found sooner rather than later.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to