473,847 Members | 1,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

difference between die and exit in php

49 New Member
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.

May 9 '10 #1
10 10593
6,050 Recognized Expert Expert
There is no difference. Simple :)
May 9 '10 #2
8,658 Recognized Expert Moderator Expert
the only notable difference is this pun:
Also note that it is your responsibility to die() if necessary.
May 9 '10 #3
1,584 Recognized Expert Top Contributor
This is actually a question in w3schools.org's PHP quiz.

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

May 10 '10 #4
6,050 Recognized Expert Expert
Expand|Select|Wrap|Line Numbers
  1. Result:
  3. 20 of 20
  4. 100%
  6. Perfect!!!
  8. Time Spent
  9. 1:57
Sweeeet ;)
May 10 '10 #5
1 New Member
die function kill the rest all the page and exit will just jump to next line or next function...that s differnce between in both
Nov 29 '12 #6
8,658 Recognized Expert Moderator Expert
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
16 New Member
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
8,658 Recognized Expert Moderator Expert
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:



This language construct is equivalent to exit().


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
Owais Arain
2 New Member
echo also outputs a message #solutionwand
Jul 9 '15 #10

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

Similar topics

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 program ended with exit(0) the program ended immediately else It would take long to exit long after return(0) was called Can anyone explain why this happens ( I am using apache on linux redhat 7.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 return value, but is there any reason to specify one rather than the other? Thanks!
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 them? Thanks a lot!
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 if they aren't, which should I use in which situation? Also I was wondering if it whould be wise to combine the standard status with return. exp:
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 obvious differece in time. Here I have an input file scales 1.1M, what I did is just copy it to another output file(ten times). But I don't think I see any difference. My file system is ext3, with debian sarge(kernel-2.6.8). Here is the main part of my program:
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 function? Can a function call (or only this exit(n)) statement provide both function call and return features of the C programming language? /* headers omitted */ int main (void)
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
by: Vicky | last post by:
Please tell me at vdkhakhkhar@gmail.com
by: Antonio Parolini | last post by:
What is the difference between: main(......) { exit(0); } and main(......) {
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 interpreting arriving at the end of the source code file. This has a semantic difference for my applications. Is there a way to determine in an exithandler (that is registered using atexit.register)
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.