Think of a problem first:
What does the following code show to the page?
There was a time I always thought the page will show 123, but the practice results tell me that the answer is wrong, the page is blank!
I don't know why, anyway. Output 123, in order to let the page output 123, I changed it to the following code:
A section of the online information:
The difference between exit () and Die () in PHP
php manual : Die () equivalent to exit ().
description : Both die () and exit () are abort script execution functions; the two names of Exit and die refer to the same function, and die () is the alias of the exit () function. The function accepts only one parameter, either a value returned by a program or a string, or a parameter without input, and the result has no return value.
Reference : Although the two are the same, there are usually subtle selectivity in use. For example:
When passed to the exit and Die function, the value of 0 o'clock means that the execution of the script is terminated prematurely, usually with the name exit ().
echo "1111"; exit (0); echo "2222" ; 22222 is not output, because the script has been terminated prematurely, "expired immediately" when the program ran to exit (0).
When a program goes wrong, it can be passed a string, which is output on the system terminal, usually using the name Die ().
$FP =fopen ("./readme.txt", "R") or Die ("Cannot open the file");//In this case, if the fopen function is called to return a Boolean value of false, die () will immediately terminate the script and immediately print//pass the string to it, " I can say one or two words before I die. "
Back to the previous topic, why does the following code not output 123 to the page?
Self-Summary:
1, function, die () is equivalent to exit ();
2, PHP has a variety of modes of operation, can be the form of Web site, but also script form (do not need a Web server).
- When PHP is running as a script, exit () is recommended:
For example, the Bash Shell scripting language, when it is going to stop running, terminates the script with the exit () function and allows the output point content to run to the environment (typically stored in a global variable), but the output can only be a number, indicating " the end state of the command ."
That is, exit (123) simply outputs a run state of 123 instead of actually outputting the string 123 to the console. If you want to output 123 to the console, the code is changed to the following form:
- When PHP is running as a Web site, it is recommended to use Die ():
But at this point Die (number), it makes no sense, because it does not output a numeric string to the page, that is, if you want to let the page terminate and output the number, you have to change to the following form
The above describes the exit and die in PHP differences, including the aspects of the content, I hope the PHP tutorial interested in a friend to help.