This article is mainly on the PHP require and require_once The difference is introduced, the need for friends can come to the reference, I hope to help you
Include () and require (): The statement includes and runs the specified file.
Include () produces a warning and require () causes a fatal error. In other words, if you want to stop processing the page when you encounter a missing file, use require (). Include () is not the case, the script will continue to run.
The require_once () statement includes and runs the specified file during the execution of the script. This behavior is similar to the Require () statement, except that if the code in the file is already included, it is not included again.
The include_once () statement includes and runs the specified file during the execution of the script. This behavior is similar to the include () statement, except that if the code in the file is already included, it is not included again. As the name implies, it will only be included once.
The 1.include () function reads the specified file into and executes the program inside.
For example: include ('/home/me/myfile ');
The program code in the file being imported is executed, and these programs have the same variable scope (variable scope) as the location of the call to the include () function in the source file at the time of execution. You can import static files from the same server, and you can even use the include () and fopen () functions to import files from other servers.
The functions of the 2.include_once () function and include () are almost identical
The only difference is that the include_once () function first checks whether the file being imported has been imported elsewhere in the program, if you do, you will not be able to import the file again (this feature is sometimes important, for example, to import a file that declares some of your own well-defined functions. , if you import the file repeatedly in the same program, an error message will occur the second time you import it, because PHP does not allow functions of the same name to be repeated for the second time.
The 3.require () function reads the contents of the target file and replaces itself with the read content.
This read-and-replace action occurs when the PHP engine compiles your program code. Instead of what happens when the PHP engine starts executing the compiled program code (the PHP 3.0 engine works by compiling one line of execution, but it changes in PHP 4.0, PHP 4.0 is the first to put the whole Once the program code is compiled, the compiled program code is executed one at a time, and no program code is executed during the compilation. Require () is typically used to import static content, and include () is suitable for importing dynamic program code.
4. As with the include_once () function, the require_once () function will first check that the contents of the target file have been imported before, and if so, the same content will not be imported again.