PHP exit,exit (0), exit (1), exit (' 0 '), exit (' 1 '), Die,return difference

Source: Internet
Author: User



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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.