views:

485

answers:

3

what are the differences in die() and exit() function in php, I think both have the same functionality. But i know there is something different in both.. what are they?

+11  A: 

There's no difference - they are the same.

PHP Manual for exit:

Note: This language construct is equivalent to die().

PHP Manual for die:

This language construct is equivalent to exit().

Marek Karbarz
then why two function :p
coderex
aliases allows programmers to use the one which is comfortable with. I remember exit better than die. Some others remember die better than exit.
thephpdeveloper
Maybe the `die` function call was created to make Perl programmers feel at home.
pavium
ok, ok.. i think need to create a "boundry" for this Question, right?:) because i want to know "why two functions". thanks for all your answers :)
coderex
this (http://php.net/manual/en/aliases.php) might give some explanation why 2 functions do the same thing
Marek Karbarz
@Sepehr - so does `exit()` - they are equivalent in every way
Marek Karbarz
+2  A: 

They are essentially the same, though this article suggest otherwise.

o.k.w
+2  A: 

They sound about the same, however, the exit() also allows you to set the exit code of your PHP script.

Usually you don't really need this, but when writing console PHP scripts, you might want to check with for example Bash if the script completed everything in the right way.

Then you can use exit() and catch that later on. Die() however doesn't support that.

Die() always exists with code 0. So essentially a die() command does the following:

<?php
echo "I am going to die";
exit(0);
?>

Which is the same as:

<?php
die("I am going to die");
?>
Icheb