PHPBuilder - A Test To See If You Write Sloppy Software Page 4



RSS Twitter
Articles Tricks And Hacks

A Test To See If You Write Sloppy Software - Page 4

by: Tim Perdue
|
March 10, 2003

Inside of functions, you should also handle all errors. The easiest thing to do is set a $feedback variable, and in your header/footer template, you always echo out that $feedback variable if it exists. This has worked well for me.

<?php

function my_function () {
    global 
$feedback;

    
//code
    
if ($error) {
        
$feedback .= 'Could Not Perform Operation XXX';
        return 
false;
    } else {
        
$feedback .= 'Operation XXX Successfully Performed';
        return 
true;
    }
}
?>

Then you simply call these functions like this:

<?php

if (my_function()) {

    
//do something

} else {

    
//handle error

}

?>
Of course, the same error checks should be performed on database updates, inserts, and deletes. Give yourself 1 point if you check all your database queries and provide proper feedback to the user.

« Previous Page
1
|
2
|
3
|
4
|
5
|
6
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Tim Perdue

Comment:



Comment:

(Maximum characters: 1200). You have characters left.