Best Code structure?
Posted: Mon May 30, 2011 11:45 am
Hi,
I have a quick question regarding the best PHP Code structure.
What is better to do:
EXAMPLE 1
Or EXAMPLE 2
Is it better to code using a technique where you go deeper and deeper in the code following only if statement is met or is it better to do simple error check and just always stays "out" of the if statements?
I bet theres not much of a difference, but overall, which way should I choose?
Thanks guys!

I have a quick question regarding the best PHP Code structure.
What is better to do:
EXAMPLE 1
Code: Select all
if( STATEMENT 1 ){
if( STATEMENT 2 ){
//EXECUTE CODE HERE
}else{
exit;
}
}else{
exit;
}Or EXAMPLE 2
Code: Select all
if (! STATEMENT 1){
exit;
}
if (! STATEMENT 2){
exit;
}
//EXECUTE CODE HEREIs it better to code using a technique where you go deeper and deeper in the code following only if statement is met or is it better to do simple error check and just always stays "out" of the if statements?
I bet theres not much of a difference, but overall, which way should I choose?
Thanks guys!