Include () and require () statements include and run the specified file. The two structures are exactly the same on the contained files, and the only difference is the handling of errors. When the require () statement encounters an error or the contained file does not exist, it stops and returns an error. Include (): continue
1. include statement
The include statement tells PHP to extract a specific file and load all its content.
<? Phpinlude "fileinfo. php"; // add other code here?>
2. include_once statement
Every time you use the include statement, it will re-import the requested file, even if the file has been imported. For example, assume fileinfo. the PHP file contains many functions. We use the include statement to import it to an existing file, and then we import another file containing fileinfo. php files, through nesting, we have added fileinfo. if the php file is imported twice, an error occurs because we try to define variables or functions with the same name multiple times. To avoid this, we use the include_once statement instead of the include statement.
<? Phpinclude_once "fileinfo. php"; // add other code here?>
If another include or include_once statement is encountered in the same file, PHP checks whether it has been imported. If yes, ignore it.
3. require and require_once statements
The potential problem with using include and include_once statements is that PHP will only try to import the file to be requested for import. even if the file is not found, the program will still execute.
When we absolutely need to import a file, we use the require statement, which is the same for the reason of using the require_once statement, so we will not go into details here.
<? Phprequire_once "fileinfo. php"; // add other code here?>
In general, we should stick to the require_once statement.