php - What is the difference between echo('exit'); die; and die('exit');? -


i have seen code this:

if(something){     echo 'exit program';     die; } ...more code 

and others use die:

if(something)   die('exit program'); ...more code 

is there inherent difference in when end program, should aware of code comes after it? etcetera

update

i asking mainly, if coding style, or if there real reason why coded 1 way versus another. not asking difference between exit , die is.

no, there no difference; both write "exit" stdout , terminate program.

i prefer die("exit") method it's less typing, easier comment out , semantically clearer.

as far "speed", why care faster? need program die quickly?

re: update

... inherent difference in when end program ...

there no difference, inherent or otherwise. they're identical. second option, die('exit'), single statement, , requires no braces when used if statement; has nothing die , blocks , flow control in c-style languages.

re: comment/second update

which way die matter of personal preference. said, they identical. choose 2nd option reasons listed above: shorter, clearer, cleaner, amounts "better" in opinion.

the difference between exit , die exit allows return non-zero status, while die returns 0. neither function "better", serve different purposes.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -