ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Pitfalls of Transactions with PHP
Subject:   code style
Date:   2003-12-18 19:36:28
From:   anonymous2
just a suggestion on code style, if you notice all the if statements, you'll see how the code keeps moving farther and farther to the right, making it hard to read and maintain if you have a lot of conditionals.


i suggest using a single do ... while(0) loop and then break at each error. it should keep the code easy to read and you won't have to indent other code if you add another conditional later.


do {
if (...) {
/* error */
$error = "blah";
break;
}


if (...) {
/* different kind of error */
$error = "blah";
break;
}


/* still here, everything checks out, go
ahead */
...


} while (0);


if ($error) {
...
}