Page 1 of 1
[PHP] To exit or die()?
Posted: Wed Jun 11, 2014 4:21 pm
by Sharlenwar
It is my understanding that these do the same thing:
http://ca2.php.net/manual/en/function.die.php
http://ca2.php.net/manual/en/function.exit.php
Now, I have been using exit. I remember that with die("You can put text here to output"). Is there a preferred way? I am going with exit and making my own debug output.
Any thoughts?
Re: [PHP] To exit or die()?
Posted: Wed Jun 11, 2014 4:47 pm
by Xaos
I've always used die(), helps in error handling because you can throw a custom message, similar to catching an exception.
Re: [PHP] To exit or die()?
Posted: Wed Jun 11, 2014 9:40 pm
by Script47
I mainly use exit and output a message through the exit, but recently have started using return.
Re: [PHP] To exit or die()?
Posted: Thu Jun 12, 2014 2:18 pm
by Sharlenwar
So it seems it is based on preference and how you do things. As I figured. I'll do what I have been doing.
Thanks for the input!
Re: [PHP] To exit or die()?
Posted: Tue Jul 15, 2014 9:44 am
by MikuzA
In debugging I prefer to use DIE() just because, it's DIE() and sounds awesome

But when I wish an exit of a code with an actual purpose, then I use exit(). However, not that often since I rarely want my php to stop until it's finished, so I use more 'return' in handling those scenarios.
Exception is that I made an IRCBOT using php and running it with php-cli on my unix server, there I had it to go exit(1) when I commanded it to 'disconnect'.
So that way I actually get the return code of the execution.. If required
But there doesn't seem to be any difference on those..
Re: [PHP] To exit or die()?
Posted: Tue Jul 15, 2014 2:00 pm
by vitinho444
I see it this way:
Die() you can setup a custom error message.
But what I like to do is:
Code: Select all
echo "<wtv>Error blablabla</wtv>";
exit();
Redirect("index.php", 2);