1.include statements
Use the Include statement to tell PHP to extract a specific file and load its entire contents
1 <? PHP 2 inlude "fileinfo.php"; 3 4 // add additional code here 5 ?>
2.include_once StatementsEach time you use the INCLUDE statement, it will re-import the requested file, even if the file has already been imported. For example, assume that
fileinfo.phpThe file contains many functions, we use the Include statement to import him into an existing file, and then we import a
fileinfo.phpThe files, through nesting, we've put
fileinfo.phpThe file was imported two times, which produces an error because we tried to define a variable or function with the same name multiple times. To prevent this from happening, we use the include_once statement instead of the include statement
1 <? PHP 2 include_once "fileinfo.php"; 3 4 // add additional code here 5 ?>
At this point, if you encounter another include or include_once statement in the same file, PHP checks to see if it has been imported and, if so, ignores it.
3.require and require_once statements
The potential problem with using the Include and include_once statements is that PHP will only attempt to import the file that was requested for import, even if the file is not found and the program will still execute. When we absolutely need to import a file, using the Require statement, the same reason for using the require_once statement, is no longer mentioned in this.
1 <? PHP 2 require_once "fileinfo.php"; 3 4 // add additional code here 5 ?>
in general, we should insist on using require_once statements.
Include and require in PHP