What are the differences between die() and exit() functions in PHP?

There's no difference between die() and exit function in PHP they are the same

The PHP Manual for exit states:

  This language construct is equivalent to die(). 

The PHP Manual for die states:

This language construct is equivalent to exit().   

What are the differences between die() and exit() functions in PHP?

However, they do the same thing, But I usually reserve die() for error-related stops and exit(for all other scripts. It just better while reading the code.

For example, I use exit() while redirecting the page it just an example for understanding 

        
        if(isset($_SESSION['ID'])) {
  header("Location:dashboard.php");
  exit();
}
        
    

Definition

The exit()  and die() function prints a message and terminates the current script.

Syntax

exit("Message goes here"); Or exit();
die("Message goes here"); or die();

Leave a comment