PHP Exit & Die Function- Tutorialpath

PHP Exit & Die Function – Welcome to all our readers on our website at As you all know that here on our website we will provide you lots of information related to the latest and newly introduced technology which help you to get updated with the latest tech. Here you will get all the useful information which is required in this tech world.

As you know technology is one of the trending part in this world. So, here again we came up with a latest and new tech information which is related to the process of creating php exit() Function. With the help of this article you will get to know the complete process of how to create php exit() Function in a step by step manner. So, simply have a look to this article and grab all the useful information which is going to be very helpful for you.

PHP | Exit & Die Function

PHP Exit & Die Function

The exit () function in PHP is an inbuilt function that is used to output a message and terminate the current script.

PHP Exit & Die Function – Must Follow Process

The exit () function only ends the execution of the script. Shutdown functions and object destructors will always be executed even if the exit () function is called.

The message that is displayed is passed as a parameter to the exit () function and it terminates the script and displays the message.

The exit () function is another name for the die function.



Parameters Used:

The exit () function in PHP accepts a parameter.

1. message : This is a mandatory parameter that specifies the message or status number to write before exiting the script.

Return Value:
It does not return any value.

Errors And Exceptions

  1. Exit () is a language construct and can be called parentheses without passing any position.
  2. If the passed condition as a parameter is an integer, that value will be used as the exit state and will not be printed.
  3. Exit state must be in the range 0 to 254 and exit state 255 should not be used as it is reserved by PHP.
//declaring variables
//terminating script with a message using exit()
exit(‘variables are equal’);
//terminating script with a message using exit()
exit(‘variables are not equal’);


variables are equal

Example 2. exit() status example


       //exit program normally

       //exit with an error code
         exit(0376); //octal


Note: This language construct is equivalent to die().

die() Function

Die () is an inbuilt function in PHP. This is used to print the message and exit the current php script. This is equivalent to the exit () function in PHP.

Syntax :


Parameters : This function accepts only one parameter and is not mandatory to be passed

  • $message : This parameter represents the message to be printed when exiting the script

Return Value : It has no value but a message is given when exiting the script.


// blank url of site
// so that die() is executed
$site = “”;// open url else die (exit)
fopen($site, “r”)
or die(“Hello friends.”);


Hello friends


So, hopefully we have shared all the basic steps that help you PHP Exit & Die Function. If you are using any of the above browsers and the steps help you to enable or disable JavaScript and PHP then just share this article with others and also let us know by leaving a comment in the comment section below So that we know how this article is useful for all of you.

Related Searches:

Leave a Reply

Your email address will not be published. Required fields are marked *