exit, exit(), exit(0), die(), die(0) - How to exit script

后端 未结 7 1967
醉梦人生
醉梦人生 2020-12-24 00:10

I believe that all of these (and even die() or die(0)) are identical. If they are not identical, which is preferred for exiting a script successfu

7条回答
  •  难免孤独
    2020-12-24 00:42

    I would say that in regards with a better semantics die($arg); should be used for an abnormal or unexpected termination, even when -of course- you still have caught it. And exit($arg); should be used for a normal (expected / controlled) end of a process, like in break; for a for or while or a switch structure but with a definitive end.

    Nevertheless .. I personally often use a general if { } else { } structure to control different branches of huge processes or output buffering so not having to use "exit" ..

    I also use die($arg) in simple error-catching semantics like in

    $db = mysql_connect([$args]) or die ($error); ...

提交回复
热议问题