4

I have seen a lot of people (first comment) hating die(); instead of exit;

As the follow-up comments on that post note, die and exit are the same - the attitude appears to be one of perception, with some feeling that one name is more appropriate in certain contexts than others.

But why does it matter? If they do the same thing, why should I care what name I use? Does death by any other name not smell as sweet?

0

2 Answers 2

5

On a functional level, both work just fine and function the same.

However which one you prefer to use comes down to how one interprets the words die and exit.

exit has more appeal over die for me personally as a word that would be used to describe a programming function. It just seems more intuitive that way.

die however just comes off as something not technical whatsoever.

1
  • 3
    Die comes from Perl, which was like the PHP of web/cgi programming before PHP became the PHP of Web programming. :-)
    – Warren P
    Jul 20, 2011 at 23:42
4

Personally I'd use die() on errors and exit() if I'm caught somewhere deep in functions and logic and come to the conclusion that I'm finished with the task at hand.

It's one of the famous quirks and debts of PHP. Fortunately, most times one can get rid of them by simply not using them or hiding them in some piece of low-level code no one will ever see and care about again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.