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?
[PHP] To exit or die()?
- Sharlenwar
- Posts: 523
- Joined: Mon May 28, 2012 7:14 pm
[PHP] To exit or die()?
Deep within the Void of Quasion, a creation.
**My Corner of the Web**
***NEW***GrindFest - My own PHP/MySQL game!
Sharlenwar's Adventures
Torn-City - Massively multiplayer online text based RPG
**My Corner of the Web**
***NEW***GrindFest - My own PHP/MySQL game!
Sharlenwar's Adventures
Torn-City - Massively multiplayer online text based RPG
Re: [PHP] To exit or die()?
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()?
I mainly use exit and output a message through the exit, but recently have started using return.
- Sharlenwar
- Posts: 523
- Joined: Mon May 28, 2012 7:14 pm
Re: [PHP] To exit or die()?
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!
Thanks for the input!
Deep within the Void of Quasion, a creation.
**My Corner of the Web**
***NEW***GrindFest - My own PHP/MySQL game!
Sharlenwar's Adventures
Torn-City - Massively multiplayer online text based RPG
**My Corner of the Web**
***NEW***GrindFest - My own PHP/MySQL game!
Sharlenwar's Adventures
Torn-City - Massively multiplayer online text based RPG
Re: [PHP] To exit or die()?
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..
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..
Why so serious?
Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
- vitinho444
- Posts: 2819
- Joined: Mon Mar 21, 2011 4:54 pm
Re: [PHP] To exit or die()?
I see it this way:
Die() you can setup a custom error message.
But what I like to do is:
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);