What are the differences between die()
and exit()
functions in PHP
?
I think both have the same functionality, but I doubt there is something different in both... what is it?
What are the differences between die()
and exit()
functions in PHP
?
I think both have the same functionality, but I doubt there is something different in both... what is it?
There's no difference - they are the same.
PHP Manual for
exit
:PHP Manual for
die
:As stated before, these two commands produce the same parser token.
BUT
There is a small difference, and that is how long it takes the parser to return the token.
I haven't studied the PHP parser, but if it's a long list of functions starting with "d", and a shorter list starting with "e", then there must be a time penalty looking up the function name for functions starting with "e". And there may be other differences due to how the whole function name is checked.
I doubt it will be measurable unless you have a "perfect" environment dedicated to parsing PHP, and a lot of requests with different parameters. But there must be a difference, after all, PHP is an interpreted language.
The result of exit() function and die() function is allways same. But as explained in alias manual page (http://php.net/manual/en/aliases.php), it says that die() function calls exit function. I think it is hard coded like below:
This is not a performance issue for small, medium and large projects but if project has billions multiply billions multiply billions processes, this happens very important performance optimization state.
But very most of people don't thinks this is a problem, because if you have that much processes, you must think more problem than if a function is master or alias.
But, exact answer is that; allways master function is more faster than alias.
Finally; Alias manual page says that, you may no longer use die. It is only an alias, and it is deprecated.
DIFFERENCE IN ORIGIN
The difference between
die()
andexit()
in PHP is their origin.exit()
is fromexit()
in C.die()
is fromdie
in Perl.FUNCTIONALLY EQUIVALENT
die()
andexit()
are equivalent functions.PHP Manual
PHP Manual for
die
:PHP Manual for
exit
:PHP Manual for List of Function Aliases:
DIFFERENT IN OTHER LANGUAGES
die()
andexit()
are different in other languages but in PHP they are identical.From Yet another PHP rant:
They are essentially the same, though this article suggest otherwise.