Parse the differences between die (), exit (), and return in php

Source: Internet
Author: User
Tags exit in
This article provides a detailed analysis of the differences between die (), exit (), and return in php. For more information, see

This article provides a detailed analysis of the differences between die (), exit (), and return in php. For more information, see

Die () stops running the program and outputs the content
Exit indicates that the program is stopped and NO content is output.
Return is the return value.
Die stops only when an error occurs.
Exit is to stop directly without running the subsequent code. exit () can display the content.
Return is the pure return value, but it does not run subsequent code.
Exit (0): The program runs normally and exits;
Exit (1): exit the program due to abnormal operation;
Return (): return function. If it is in the main function, it will exit the function and return a value.
Details:
1. return returns the function value, which is a keyword; exit is a function.
2. return indicates the language level. It indicates the return of the Call Stack, while exit indicates the system call level and server space. It 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. It is provided by the Hong Kong virtual host, 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. the calling of return and exit in non-main functions is very effective. The Hong Kong server, but the calling of return and exit in the main function is very vague. In most cases, they are consistent.

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.