I
I
Ivan Lissitzky2012-01-25 12:34:52
PHP
Ivan Lissitzky, 2012-01-25 12:34:52

What do you use to interrupt the execution of a PHP program?

It somehow happened that I myself always use exit(). But very often I meet in various scripts, products written in PHP, the use of die () for the same purposes. The ratio of both is about the same.

According to the documentation, die() is a complete synonym for exit(), but the prerequisites for using one or another function are curious.

Answer the question

In order to leave comments, you need to log in

8 answer(s)
S
Sergey Beresnev, 2012-01-25
@sectus

NEITHER ... (unless, of course, you need to give out a code).
Throw an exception.

V
Vitaly Zheltyakov, 2012-01-25
@VitaZheltyakov

I use exit to indicate the end of script execution in the master file.
The reason is simple: exit - exit; die - to die.
I somehow associate the end of script execution with exit, not death.

S
Sergey, 2012-01-25
Protko @Fesor

die has one difference - the ability to output "posthumous data". Well, tobish, you can submit a string as an argument (an error message, something for debugging ...) and see. If you don’t need to display anything before the script ends (meaning immediately before), then you can use exit(). And so it is logical to reduce 2 lines of code into one.

S
skvot, 2012-01-25
@skvot

Depends on the size of the script. In large projects, exceptions, in one-time die() scripts. exit() in console applications.

S
SharkyFLY, 2012-01-25
@SharkyFLY

I somehow always use die() out of habit ...

C
charon, 2012-01-25
@charon

in the working program I try to intercept the error, write it to the log and finish with exit(0). Recently, in service scripts, I throw an exception and sometimes I catch it, display it on the screen and do exit ().

S
shagguboy, 2012-01-25
@shagguboy

I'm slowly moving towards exceptions. there the standard message gives more debug information

O
Ogra, 2012-01-25
@Ogra

I use die. I must have manic tendencies.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question