Mission of this functions is ended working programs. The biggest difference between die function and exit is you can show a message when a program ended by die function.
For Example:
<?php
if($a==10)
{
die("Program was ended");
} else
{
echo "program is continueing"
}
?>
In here, program will be ended because of $a=10 and it will bring string from function of die. If we want to make same example in exit :
<?php
$a=10;
if($a==10)
{
echo "Program was ended";
exit();
} else{
echo "Program is continueing." ;
}
?>
As you see, we have to write echo function. For this reason, we prefer die function. For example, if you have a problem in connection to database, you can show a warning message and you can stop the connection.
No comments:
Post a Comment