Home > Article > Backend Development > Introduction to the differences between die(), exit(), and return in php
In the process of learning PHP, you will encounter die(), exit(), and return. This article will explain the differences between die(), exit(), and return.
die() stops the program running and outputs the content
exit stops the program running and does not output the content
return is the return value
die is encountered Stop only when error occurs
exit stops directly and does not run subsequent code. exit() can display the content.
return is a pure return value, but subsequent code will not be run.
exit(0): Run the program normally and exit the program;
exit(1): Abnormal operation causes the program to exit;
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 is at the language level, which represents the return of the call stack; exit is at the system call level, which represents the end of a process.
3. Return is the exit (return) of the function; exit is the exit of the process.
4. Return is provided by C language, and exit is provided by the operating system (or given in the function library).
5. Return is used to end the execution of a function and transfer the execution information of the function to other calling functions; the exit function is to exit the application, delete the memory space used by the process, and transfer a The status is returned to the OS. This status identifies some running information of the application. This information is related to the machine and operating system. Generally, 0 means a normal exit, and non-0 means an abnormal exit.
6. The effect of calling return and exit in a non-main function is very obvious, but the phenomenon of calling return and exit in the main function is very vague. In most cases, the phenomenon is the same
This article The differences between die(), exit(), and return will be explained. For more related content, please pay attention to the PHP Chinese website.
Related recommendations:
The difference between on condition and where condition in SQL
About the method of compressing CSS code in PHP
PHP receives json and inserts the received data into the database
The above is the detailed content of Introduction to the differences between die(), exit(), and return in php. For more information, please follow other related articles on the PHP Chinese website!