Take the 2-minute tour ×

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?

share|improve this question
+1 for this funny question title. –  Mulmoth Aug 22 '11 at 6:56
add comment

2 Answers

up vote 5 down vote accepted

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.

share|improve this answer
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 '11 at 23:42
add comment

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.

share|improve this answer
add comment

Your Answer


