472,353 Members | 1,587 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

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 10306
Markus
6,050 Expert 4TB
There is no difference. Simple :)
May 9 '10 #2
Dormilich
8,658 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,658 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,658 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

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

Similar topics

2
by: Ramprasad A Padmanabhan | last post by:
If I have defined my main function as int Then does it make a difference I end main by return(0) or exit(0) Because I noticed that When My cgi...
2
by: fwee | last post by:
What is the difference between using exit(n) and return n in main(), if any? I know that exit(n) is a function that exits and return n exits via a...
5
by: QQ | last post by:
I know there are many functions that I can exit the program such as return 0, exit(0), exit(1),_EXIT(0) .... What are the difference between...
17
by: jwaixs | last post by:
Hello, I was wondering, what's the difference between exit and return in the main() function? For me they both look the same, or aren't they? And...
4
by: pank7 | last post by:
hi everyone, I have a program here to test the file IO(actually output) with buffer turned on and off. What I want to see is that there will be...
20
by: lovecreatesbeauty | last post by:
Hello experts, Is the following code snippet legal? If it is, how can exit() do the keyword return a favor and give a return value to the main...
14
by: tshad | last post by:
Is there any difference between Return and Exit Sub? I have some code that uses both when I have an error in my Sub. Thanks, Tom
6
by: Vicky | last post by:
Please tell me at vdkhakhkhar@gmail.com
5
by: Antonio Parolini | last post by:
What is the difference between: main(......) { exit(0); } and main(......) {
3
by: carl.dhalluin | last post by:
Hi, I am playing with the atexit module but I don't find a way to see the difference between a script calling sys.exit(<returncode>) and the...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.