Difference between die() and exit() functions in PHP Last Updated : 10 Nov, 2022 Comments Improve Suggest changes Like Article Like Report PHP exit() Function: In PHP, the exit() function prints a message and exits the application. It's often used to print a different message in the event of a mistake. Use exit() when there is not an error and have to stop the execution. Syntax: exit("Message goes here"); or exit(); Example: exit("This request is processed"); Program 1: PHP <?php exit ("This is an exit function in php"); echo "This will not printed because " . "we have executed exit function"; ?> Output: This is an exit function in php Program 2: PHP <?php $a = 10; $b = 10.0; if($a == $b) { exit('variables are equal'); } else { exit('variables are not equal'); } ?> Output: variables are equal PHP die() Function: In PHP, die() is the same as exit(). A program's result will be an empty screen. Use die() when there is an error and have to stop the execution. Syntax: die("Message goes here"); or die(); Example: die('Oops! Something went wrong'); Program: PHP <?php $num = 1; // die can only print string values, // hence there will be no output die($num); ?> Output: No Output Note: The output for the above program will be an empty screen because it is similar to exit(), die() can print only string values. Differences between die() and exit() Functions: die() exit() The die() method is used to throw an exceptionThe exit() method is only used to exit the process.The die() function is used to print the message.The exit() method exits the script or it may be used to print alternate messages.This method is from die() in Perl.This method is from exit() in C. Comment More infoAdvertise with us Next Article Difference between die() and exit() functions in PHP S sanketnagare Follow Improve Article Tags : Difference Between Web Technologies PHP PHP-Questions Web Technologies - Difference Between +1 More Similar Reads Difference between isset() and empty() Functions The isset() and empty() functions in PHP are used for variable checking but serve different purposes. isset() checks if a variable is set and not null, while empty() checks if a variable is considered empty, like 0, false, null, or an empty string.Table of Contentempty() Functionsisset() FunctionDif 5 min read What is the difference between fopen() and fclose() functions in PHP ? In this article, we are going to discuss the differences between fopen() and fclose() functions. fopen() function: This function helps users to open a file or a web URL. It mainly accepts two parameters - One is $file that specifies the file or an URL to be opened and the other is $mode that specifi 2 min read Explain the Difference Between shell_exec() and exec() Functions In this article, we will learn about the shell_exec() & exec() functions in PHP. As we know that in order to execute a command in a system, we need the shell of the respective operating systems, but if we need to execute the same command with the help of a programming language like PHP, then we 4 min read Difference between runtime exception and compile time exception in PHP The term PHP is an acronym for Hypertext Preprocessor, which is a server-side scripting language designed specifically for web development. It is open-source which means it is free to download and use. It is very simple to learn and use. The files have the extension â.phpâ. It is an interpreted lang 3 min read Difference between mysql_connect() and mysql_pconnect() Functions in PHP mysql_connect() Function: The mysql_connect() function is used to establish a new connection with the database. This connection is established when the script starts its execution. After establishing this connection with the database, it will be valid or be connected with the database only until the 3 min read Difference between include() and include_once() in PHP The include() function in PHP is mostly used to include the code/data of one PHP file to another file. During this process if there are any kind of errors then this require() function will display/give a warning but unlike the require() function in which the execution comes to a halt, the include() 3 min read What is the difference between == and === in PHP ? In this article, we will discuss the differences between '==' and '===' operators in PHP. Both are comparison operators used to compare two or more values. == Operator: This operator is used to check the given values are equal or not. If yes, it returns true, otherwise it returns false. Syntax: oper 2 min read Difference between the (=), (==), and (===) operators in PHP In PHP, the '=' operator is used for assignment, while the '==' operator is used for loose equality comparison, meaning it checks if two values are equal without considering their data types. On the other hand, the '===' operator is used for strict equality comparison, meaning it checks if two value 3 min read Difference between require() and include() in PHP In this article, we will see the require() and include() Functions in PHP, along with understanding their basic implementation through the illustration. Both require() and include() Functions are utilized to add the external PHP files in the current PHP script. With this, both functions enhance the 3 min read Difference between std::quick_exit and std::abort std::quick_exit() It Causes normal program termination to occur without completely cleaning the resources. Syntax : void quick_exit(int exit_code) no except; In case of execution of threads the codes becomes complex and knowing the execution of threads is hard. While one the thread might be waiting 3 min read Like