tags:

views:

60

answers:

3

Hello all,

I have just come across this code:

function test(){

//...

if ( $profilerule == "profile" and $operator != "=" ) {
       verbatimlogit('false');
       break;
}

//...

}

Is it just me or will that break not work there?! There isn't even a loop. A continue work either, right?

I just want a confirmation here as I am pretty sure this is the case.

+4  A: 

According to the PHP docs of the break keyword, this would be an invalid structure (unless there was a loop in the code you removed.)

soulmerge
Thats how I understood it, thank you for the confirm!
Abs
+2  A: 

From the PHP Documentation:

break ends execution of the current for, foreach, while, do-while or switch structure.

So yes, inside an if, it's invalid (unless that if is within one of the above structures).

Dominic Rodger
+2  A: 

What exactly are you trying to do?

If you're trying to end execution of the function, you'd probably just want to use the return() statement.

http://us.php.net/return

AvatarKava