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
2009-11-25 06:30:16
then why two function :p
coderex
2009-11-25 06:33:00
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
2009-11-25 06:35:56
Maybe the `die` function call was created to make Perl programmers feel at home.
pavium
2009-11-25 06:56:25
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
2009-11-25 07:08:57
this (http://php.net/manual/en/aliases.php) might give some explanation why 2 functions do the same thing
Marek Karbarz
2009-11-25 07:17:34
@Sepehr - so does `exit()` - they are equivalent in every way
Marek Karbarz
2010-06-27 00:10:27
+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
2009-11-25 08:19:20