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

不言
Release: 2023-03-23 08:50:02
Original
1650 people have browsed it

This article is a detailed analysis and introduction to the differences between die(), exit(), and return in php. Friends who need it can refer to it

die()Stop the program running and output the content
exit is to stop the program running and do not output the content
return Is the return value
die It stops when it encounters an error
exit It stops directly and does not run subsequent code , exit() can display the content.
return is a pure return value, but the 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 the 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 the application A status of the program 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 obvious, but calling return and # in the main function The phenomenon of ##exit is very vague. In most cases, the phenomena are consistent

##

The above is the detailed content of Analysis of the differences between die(), exit(), and return in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template