13:57 - Saturday, 19 April 2014

Why Are People Afraid To Die()?

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?

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.

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.