Evan Stoddard
Evan Stoddard

Reputation: 708

Is break; required after die() php

I've been thinking to much...

In the area of switch case is break; required after die()

Example:

switch($i){

     case 0:
          die('Case without break;');

     case 1:
          die('Case with break;');
          break;

}

Upvotes: 5

Views: 1386

Answers (3)

Aris
Aris

Reputation: 5055

it's not required. Even for the switch break is not mandatory. If no break is in one case, it just keeps executing the next.

but after die, it makes no difference, since die terminates the program execution. Just hope you don't plan to use die inside some cases.

Upvotes: 4

hek2mgl
hek2mgl

Reputation: 158070

die() is just an alias for exit(), where exit() will terminate the program flow immediately. (Shutdown functions and object destructors will still get executed after exit())

And no, it is not a syntax error to omit the break, on the contrary there are many useful cases for omitting the break. Check the manual page of the switch statement for examples.

Upvotes: 6

Cameron Tinker
Cameron Tinker

Reputation: 9789

Syntactically, it is not required, but it won't be executed since die() causes the execution to stop.

Upvotes: 1

Related Questions