[Php] the core features of include, include_once, require, and require_once are the same, it is equivalent to directly copying the code of the target webpage.
Basically, if you do not consider performance, you can use include, include_once, require, and require_once to achieve basic results. Basically, you can use it whenever you like.
The minor differences are as follows:
For example, 1. php has a simple print statement:
The following program running result:
It must be 2 to 1 instead of 4 to 1. because both include and require introduce the specified file, _ once indicates that the file is only introduced once, that is, the previously introduced file is not introduced.
If it is written:
The result is 4 to 1.
Region:
Untitled Document
If you have the following statements:
The result is as follows:
The same part appears twice. _ Once is used only to determine whether or not the file has been introduced before by using the file name.
Therefore, _ once cannot prevent multiple accesses to the same resource with different names.
In addition to processing imported files, include and require have different methods. The biggest difference is that include generates a warning when introducing non-stored files and the script continues to run, require may cause a fatal error and the script is stopped.
For example, if a. php does not exist, the following code will still output B:
And:
No.
There are also the following differences:
Include () is a conditional include function, while require () is an unconditional include function.
If (FALSE) {include 'File. php '; // file. php will not be introduced} if (FALSE) {require 'File. php '; // file. php will be introduced}Include has a return value, while require does not
$ RetVal = include ('somefile. php'); if (! Empty ($ retVal) {echo "file inclusion succeeded";} else {echo "file inclusion failed ";}Yes.
Include () is used to read and evaluate the files to be referenced during execution, and require () is used to process the files to be referenced only once, in fact, the require () statement is replaced with the file content to be referenced during execution. it can be seen that if there is code containing one of these commands and code that may be executed multiple times, require () is used () high efficiency. if different files are read each time the code is executed, or there is a loop through a set of file stacks, the include () method is used ().
Require is usually used. 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, make it a part of the PHP web page. This method can also be used to introduce common functions into webpages. Include is usually used. This function is generally placed in the processing part of process control. The PHP program webpage reads the include file. In this way, you can simplify the process during program execution.
In addition, the question about whether to add parentheses after include and require is theoretically: adding parentheses after include and require makes no difference in execution results, but it is inefficient to add parentheses, therefore, no parentheses can be added to the end.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.