469,282 Members | 2,000 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

difference between die and exit in php

hello everybody,

I want to know the exact difference between exit and die function in php.I searched it out on google,but didn't find satisfactory answer.I found both are alias of each other,but I guess there must be some difference,so please help me out.


Thanks...
May 9 '10 #1
10 10104
Markus
6,050 Expert 4TB
There is no difference. Simple :)
May 9 '10 #2
Dormilich
8,651 Expert Mod 8TB
the only notable difference is this pun:
Also note that it is your responsibility to die() if necessary.
(ref.)
May 9 '10 #3
dlite922
1,584 Expert 1GB
This is actually a question in w3schools.org's PHP quiz.

I remember missing that question and that's why I always remember this.





Dan
May 10 '10 #4
Markus
6,050 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. Result:
  2.  
  3. 20 of 20
  4. 100%
  5.  
  6. Perfect!!!
  7.  
  8. Time Spent
  9. 1:57
Sweeeet ;)
May 10 '10 #5
die function kill the rest all the page and exit will just jump to next line or next function...thats differnce between in both
Nov 29 '12 #6
Dormilich
8,651 Expert Mod 8TB
I doubt that. from the Manual:
[exit] Terminates execution of the script. Shutdown functions and object destructors will always be executed even if exit is called.
Nov 29 '12 #7
Hi,
There is no difference in functionality. They can be used alternatively with following conditions.

die > is used to throw an exception (catchable using eval).
exit > is used to exit the process.

die > will set the error code based on $! or $? if the exception is uncaught.
exit > will set the error code based on its argument.

In short,

die > outputs a message
exit > does not outputs message

Hope this shall help you to understand the difference.
Dec 20 '12 #8
Dormilich
8,651 Expert Mod 8TB
die > is used to throw an exception (catchable using eval).
wrong. neither does die throw an Exception, nor does eval catches one.

let’s get some more precise and quote the Manual:

die:

Description

This language construct is equivalent to exit().

exit:

Description
void exit ([ string $status ] )
void exit ( int $status )

Terminates execution of the script. Shutdown functions and object destructors will always be executed even if exit is called.

exit is a language construct and it can be called without parentheses if no status is passed.
Dec 26 '12 #9
echo also outputs a message #solutionwand
Jul 9 '15 #10
Sorry i m so late, i didn't see the date of this post. :P
Jul 9 '15 #11

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Ramprasad A Padmanabhan | last post: by
17 posts views Thread by jwaixs | last post: by
20 posts views Thread by lovecreatesbeauty | last post: by
14 posts views Thread by tshad | last post: by
6 posts views Thread by Vicky | last post: by
5 posts views Thread by Antonio Parolini | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.