Die (' 1 ') Die () and exit () are all 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.
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";
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 this file");
// In this case, if the fopen function is called and returns a Boolean value of false, die () will immediately terminate the script and print immediately
// The string passed to it, "Can say one or two words before death".
The same die (' 1 ') also goes through exit (' 1 '), Output 1
echo "begin";
die (‘1‘);
echo "end"; // output begin1
Exit (1) Do not output content, end program
echo "begin";
exit (1);
echo "end";
// output begin
Exit (0) do not output content, end program
echo "begin";
exit(0);
echo "end"; //output begin
Exit (' 0 ') output 0 and end the program
echo "begin";
exit(‘0‘);
echo "end"; // output begin0
Exit (' 1 ') Output 1 and end the program
echo "begin";
exit(‘1‘);
echo "end"; //output begin1
return value, the subsequent program is not executed, the value is not output
echo "begin";
return 1;
echo "end";
// output begin, the value of return is not output to the screen, but is returned to the previous layer
Summarize:
return is the return value, die is stopped when encountering an error, exit is a direct stop, and the subsequent code is not run, and exit () can display the content. return is a pure return value, but it will not run subsequent code exit (0): Run the program normally and exit the program; exit (1): Exit the program due to abnormal operation; The difference between exit, exit (0), exit (1), exit ('0'), exit ('1'), die, return in PHP |
|
PHP exit,exit (0), exit (1), exit (' 0 '), exit (' 1 '), Die,return difference