Abs
Abs

Reputation: 57966

Break - wrong place?

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.

Upvotes: 0

Views: 83

Answers (3)

AvatarKava
AvatarKava

Reputation: 15453

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

Upvotes: 2

Dominic Rodger
Dominic Rodger

Reputation: 99811

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).

Upvotes: 2

soulmerge
soulmerge

Reputation: 75744

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.)

Upvotes: 4

Related Questions