Break required; after die () php

I thought a lot ...

In the area of ​​the switch enclosure break; required after die()

Example:

 switch($i){ case 0: die('Case without break;'); case 1: die('Case with break;'); break; } 
+4
source share
3 answers

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

And no, this is not a syntax error to omit break , on the contrary, there are many useful cases for eliminating break . See the switch manual page for an example.

+6
source

it is not required. Even for a switch, break is optional. If in one case a break does not occur, it simply continues with the next.

but after die it doesn’t matter, since die terminates the program. Just hope you do not plan to use die in some cases.

+3
source

It is not required syntactically, but it will not be executed, since die() causes the execution to stop.

+1
source

Source: https://habr.com/ru/post/1496222/


All Articles