The difference between require and include in PHP is: when the file to be included does not exist, include will generate a warning (Warning), and the program following the statement will continue to execute; while require will generate a fatal error ( Fatal error), the program terminates.
include If two files are imported with the same function name, a redefinition error will occur. This error can be avoided by using include_once. Generally, _once is used more often.
The difference between include and require
When the file to be included does not exist, include generates a warning (Warning), and the program following the statement will continue to execute ; and require results in a fatal error (Fatal error) and the program terminates.
include_once and require_once
should be used when the same file may be included more than once during script execution and you want to ensure that it is only included Once to avoid problems such as function redefinition and variable reassignment.
1.include is loaded when used. This function is usually placed in the processing section of the process control.
2.require is loaded at the beginning. This function is usually placed in The first
3._once suffix of the PHP program indicates that the loaded one is not loaded
Recommended tutorial: "php tutorial"
The above is the detailed content of What are the differences between php require and include?. For more information, please follow other related articles on the PHP Chinese website!