PHP files include, include_once, require, and require_once statements.
1. Include ()
Include (/path/to/filename)
The include () Statement will contain a file at the location where it is called. A file contains the same content as the data copied to the file where the statement is located.
Parentheses can be ignored when include () is used.
You can execute the include () statement according to the conditions. The use of include () in conditional statements has a strange phenomenon. It must be enclosed in statement block braces or enclosed by other statements.
2. include_once ()
Include_once (filename)
The role of the include_once () function is the same as that of the include function, but it will first verify whether the file is included. If it already exists, revoke de_once is not executed. Otherwise, the file must be included. This is the same as include.
3. Require ()
Require (filename)
To a large extent, require () is the same as include. A template file is included in the location where the require call is located.
There are two important differences between require and include. First, regardless of the location of require, the file will be included in the script where require appears. For example, even if require is placed in an if statement whose calculation result is false, it still contains the specified file.
The second important difference is that when a require error occurs, the script stops running, and the script continues to run when the include is used.
4. require_once ()
Require_once (filename)
As the website grows bigger, some files may be repeatedly contained. This may not be a problem, but after modifying the variable of the included file, it is overwritten because it contains the original file again. This may not happen. Another problem may also occur, that is, the conflict of letters in the file. Use require_once to solve these problems.
The require_once function ensures that the file is only contained once. If you encounter require_once and try to include the same file later, it will be ignored.