PHP exit and die function- Tutorialpath

Welcome to all our readers on our website at www.tutorialpath.com. 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( ) Function

exit-vs-die-php
exit-vs-die-php

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

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.

Syntax:

exit(message)

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.
<?php
//declaring variables
$a=5;
$b=5.0;if($a==$b)
{
//terminating script with a message using exit()
exit(‘variables are equal’);
}
else
{
//terminating script with a message using exit()
exit(‘variables are not equal’);
}
?>

Output:

variables are equal

Example 2. exit() status example

<?php

       //exit program normally
         exit;
         exit();
         exit(0);

       //exit with an error code
         exit(1);
         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 :

die($message)

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.

Example:

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

Output:

Hello friends

Conclusion:

So, hopefully we have shared all the basic steps that help you php the exit() and 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 *