Programming structures
| From: | alex | Date: | Sat, 24 Jun 2000 23:38:58 +0000 |
| Subject: | Programming structures | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-2935@lists.php.net to get a copy of this message | ||
I'm trying to figure out what's the best way to structure all my code and I
have some doubts about it.. here are some thoughts:
When it comes to handling errors I usually do one of the following:
<?
$foo = my_function();
if (!$foo){
echo "some text explaining the problem";
} else {
... rest of the code....
}
?>
or just:
<?
$foo = my_function() or die("some text explaining the problem");
?>
I would allways use the die() alternative, since it's much more readable
than the "if/else" solution. On the other hand, making your script die is
not so nice, for example I usually require() some footer.inc's at the end of
the scripts that wouldn't get executed with the die() before it. That's why
I mostly use the "if/else" structure for handling errors. My problem comes
when I have to nest lots of if/else structures in the code, it becomes a lot
more complicated to read.
Are there other better alternatives than the ones I've showed up in the
examples above?
What's your prefered way to handle that kind of problems?
any hints would be great!
Alex V.