[PHP] To exit or die()?

C++, C#, Java, PHP, ect...
Post Reply
User avatar
Sharlenwar
Posts: 523
Joined: Mon May 28, 2012 7:14 pm

[PHP] To exit or die()?

Post 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?
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
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Re: [PHP] To exit or die()?

Post by Xaos »

I've always used die(), helps in error handling because you can throw a custom message, similar to catching an exception.
User avatar
Script47
Posts: 147
Joined: Thu Nov 21, 2013 6:11 pm

Re: [PHP] To exit or die()?

Post by Script47 »

I mainly use exit and output a message through the exit, but recently have started using return.
User avatar
Sharlenwar
Posts: 523
Joined: Mon May 28, 2012 7:14 pm

Re: [PHP] To exit or die()?

Post 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!
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
User avatar
MikuzA
Posts: 394
Joined: Thu Aug 08, 2013 8:57 am

Re: [PHP] To exit or die()?

Post by MikuzA »

In debugging I prefer to use DIE() just because, it's DIE() and sounds awesome :D
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
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

Re: [PHP] To exit or die()?

Post 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);
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
Post Reply

Return to “Coding”