Answer the question
In order to leave comments, you need to log in
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
NEITHER ... (unless, of course, you need to give out a code).
Throw an exception.
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.
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.
Depends on the size of the script. In large projects, exceptions, in one-time die() scripts. exit() in console applications.
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 ().
I'm slowly moving towards exceptions. there the standard message gives more debug information
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question