There are two methods to reference files: require and include. The two methods provide different elasticity.
The use of require is as follows:require("MyRequireFile.php");
. This function is usually placed at the beginning of the PHP program. Before the PHP program is executed, it will first read the file specified by require to make it a part of the PHP program webpage. This method can also be used to introduce common functions into webpages.
The require file has an error and the main program has stopped.
The use of include is as follows:include("MyIncludeFile.php");
. This function is generally placed in the Process of process control. The PHP program webpage reads the include file. In this way, you can simplify the process during program execution.
If an error occurs in the include file, the main program continues to execute.
The difference between require and include is that when an error occurs, one is error and the other is warning.
Include has a return value, but require does not (probably because so require is faster than include)
$ Login = include ('test. php ');
If (! Empty ($ login )){
Echo "File Inclusion succeeded ";
} Else {
Echo "File Inclusion failed ";
}
Include is generally used to load templates, foreach loop bodies, configuration files, and cache files. Avoid fatal errors.
Require is generally used to load functions and classes.