Parsing differences between die (), exit (), and return in php _ PHP Tutorial

Source: Internet
Author: User
Parse the differences between die (), exit (), and return in php. Die () stops running the program. The Output Content exit indicates that the program is stopped. If no output content return indicates that the return value is die. If an error occurs, exit indicates that the program is stopped directly, and subsequent code is not run. Die ()Stop program running and Output Content
ExitIs to stop the program running, no output content
ReturnYesreturn value
DieStop only when an error occurs.
ExitIs to stop directly without running the subsequent code, exit () can display the content.
ReturnIt is a pure return value, but it does not run subsequent code.
Exit (0 ):Run the program normally and exit the program;
Exit (1 ):Exit the program due to abnormal operation;
Return ():Returns the function. if it is in the main function, it exits the function and returns a value.
Details:
1. return returns the function value, which is a keyword; exit is a function.
2. return indicates the language level, which indicates the return of the call stack, and exit indicates the system call level, which indicates the end of a process.
3. return indicates the exit of the function (return); exit indicates the exit of the process.
4. return is provided in C language, and exit is provided by the operating system (or provided in the function library ).
5. return ends the execution of a function, and transmits the execution information of the function to other calling functions. the exit function exits the application and deletes the memory space used by the process, return a state of the application to the OS, which identifies some running information of the application. This information is related to the machine and the operating system. generally, 0 indicates that the application exits normally, if the value is not 0, the system exits abnormally.
6. calls from non-main functions ReturnAnd ExitThe effect is obvious, MainFunction call ReturnAnd ExitIn most cases, the phenomena are consistent.

Http://www.bkjia.com/PHPjc/327675.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/327675.htmlTechArticledie () stop program running, output content exit is to stop program running, do not output content return value die is encountered error to stop exit is to stop directly, and do not run subsequent code...

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.