-
Similarities: both include and require can include another file in the current file. Differences:
When include is used, when the included file does not exist, the system will report a warning level error, and the program will continue to execute. When using require to include a file, when the included file does not exist, the system reports a warning level error first, followed by a fatal level error. The program will be terminated.
Require makes PHP programs more efficient, and after being explained once in the same PHP file, it will not be explained a second time. include, on the other hand, repeats the interpretation of the included files. So when php pages are introduced using loops or conditional statements.
file,"require"It will not make any changes when this happens, it must be used"include"command to bring in the file.
-
equire->require is a non-contaminating condition that contains the require, that is, if a require is added to a process, the require will be executed first regardless of whether the condition is true or not
include->include has a return value, while require does not (probably because of this, require is faster than include).
Note: require is a laughing error when the include file does not exist or has a syntax error, not include.
Use. require_once()
And. include once() can avoid including the same file multiple times to avoid function redefinitions, variable reassignments, etc.
Returns the value and . include()
Same. If the file is already included, this function returns.
true。Note Absolute Shengdan:
require once() is. php
Newly added.
-
The include part issues a warning if an error occurs in execution, but the rest of the page continues.
If an error occurs in the partial execution of the require, the system will send a fatal error message and the page will terminate the execution.
-
There are two main types of citation methods in PHP, which are:
include (subdivided into include and include once).
require (subdivided into require and require once).
Both classes can insert the contents of a php file into another php file (before the server executes it). But there is a certain difference in error handling.
require generates a fatal error (e compile error) and stops the script.
include only generates a warning (e warning) and the script continues.
So be clear when using it.
If your program needs to continue running even if it is referencing an error, use include (e.g., a file that is not very important. Files that don't have a big impact on the results. )
If the reference fails, it will be stopped immediately, and the integrity of the program must be ensured, then require is used(e.g., a document that is processed for currency calculations, which will have a great impact on the results and is very important.) )
include once and require once
These two are the same as include and require when handling errors, but when referencing files with include once and require once, referencing only once can avoid errors when referencing multiple times.
In practice, it is recommended to use include once and require once to refer to a file, which can not only achieve the original purpose, but also avoid errors caused by multiple references.
-
The two ways provide different flexibility of use.
The use of require is usually placed at the top of the php program, and the php program will read the file specified by require before it is executed, so that it becomes part of the php program's web page. Commonly used functions can also be introduced into web pages in this way.
The include method is usually placed in the processing section of the process control. The php program web page only reads the include file when it reads it. In this way, the process of program execution can be simplified.
-
1. The way to load files is different.
For the include() statement, it needs to be read and evaluated every time the file is executed;
In the case of require(), the file is processed only once (in effect, the file content replaces the require() statement).
2. Different scenarios are used:
If you read a different file each time you execute **, or if there is a loop that iterates through a set of files, use the include() statement.
Require can be used as follows: require(""This statement is usually placed at the top of a PHP script.
The include method is the same as require, as in :include(""), and this statement is usually placed in the processing section of the process control.
3. Differences in use:
When include introduces a file, if you encounter an error, it will give a prompt and continue to run the following **.
When requiring to import a file, if an error is encountered, it will give a prompt and stop running the ** below.
For example, if you write two PHP files with the name and the same directory, be careful not to have a file with the name yes in the same directory.
** As follows: include'';
echo 'abc';
**As follows: require'';
echo 'abc';
Browse because we didn't find the file, we saw an error message, and at the same time, the abc is displayed below the error message, and what you see may be similar to the following situation:
Browsing because we didn't find the file, we saw an error message, however, the error message does not show abc below, what you see may be similar to the situation below:
-
One sentence explanation is that include can't find the file doesn't report an error, and require can't find a file and reports a fatal error.
-
1.The difference between require and include (which is also the difference between include once and require once).
The similarity is that both can be introduced to other pages; The difference is: include if the program has an error, it will continue to execute, and if require has an error, the program will be terminated.
2.When we are developing a program, it is recommended to use require once; This makes it possible to quickly find out the program errors.
3.Pay attention to our require once require....It should be placed at the top of the php page.
-
Both include and require are used to import a file.
The difference is that when the file does not exist, include will prompt, and then **continue to run require will be wrong, and then php will be terminated.
-
require can add judgment conditions, such as if (true).
And include
For example, if (true).
-
Both functions function the same, with the following differences:
The program is executed from top to bottom, and when it encounters an include, it will be loaded once.
Regardless of where the require is written, it will be loaded at the beginning of the program's run.
-
I just searched and found it.
-
To put it simply, if the include function reports an error, it will report an error, but the following ** can still be executed, but require will report a fatal error, and the following ** cannot be executed.
-
Both are imported files, but include will not report an error if the file cannot be found, and require will report an error that makes the program unable to execute.
-
Difference from require.
The use of require is usually placed at the beginning of a php program, and before the php program is executed, it will read the file specified by require to make it part of the php program's web page. Commonly used functions, you can also use this method to introduce it into a web page.
The include method is usually used in the processing section of the process control. The php program web page only reads the include file when it reads it. In this way, the process of program execution can be simplified.
include() also functions in much the same way as require(), but there are some differences in usage, include() is a conditional inclusion function, while require() is an unconditional inclusion function. For example, in the following **, if the variable $a is true, the file will be included:
if($a)
require() is different from include() in that the following ** will include the file in the file, regardless of the value of $a:
if($a)
If there is an error in a file, the program will be interrupted and a fatal error will be displayed.
If there is an error in the include file, then the program will not be mid-range, but will continue to execute with a warning error.
and include once() statements.
As an aside, the simple require once() and include once() statements correspond to the require() and include() statements, respectively. The require once() and include once() statements are mainly used when multiple files need to be included, which can effectively avoid the error of duplicate definition of functions or variables by including the same paragraph.
3.The load address parameter is not available, and the variable value of the current file can be read directly.
-
In fact, the biggest difference between the two is the difference in the error handling method, and there are some small differences, as follows:
include has a return value, while require does not.
include() includes and runs the specified file, and when the processing fails, include() produces a warning, and the imported programs will be executed, and these programs will have the same range of variables as the position called to the include() statement in the source file. You can import static pages from the same server.
include once() will first check if the file to be imported has already been imported elsewhere in the program, and if so, it will not be imported again (this feature is sometimes very important, for example, if you want to import some functions that you have defined yourself, then if you import the file repeatedly in the same program, an error message will occur on the second import, because PHP does not allow functions with the same name to be redefined).
require() will read in the contents of the target file, and replace itself with the contents of those reads, and if the processing fails, require() will result in a fatal error.
This read-and-replace action occurs when the PHP engine compiles your program, not when the PHP engine starts to execute the compiled program (the way the PHP engine works is to compile a line and execute a line, but it has changed after PHP, PHP is to compile the entire program ** completely, and then execute these compiled programs ** at once, and no program will be executed in the compilation process**). require() is usually used to import static content, while include() is suitable for importing dynamic programs**.
As with include once(), require once() will first check if the contents of the target file have been imported before, and if so, will not import the same content again.
Require is unconditionally included, that is, if a require is added to a process, the require will be executed first regardless of whether the condition is true or not.
Require is usually placed at the front of the PHP program, and before the PHP program is executed, it will read the file specified by Require to make it part of the PHP program's web page. Commonly used functions, you can also use this method to introduce it into a web page.
Include is usually placed in the processing part of the process control, and the PHP program web page reads the include file before it reads it. In this way, the process of program execution can be simplified.
session is temporary until the link is closed, and the cookie is persistent until the browser is emptied.
The session is divided into two parts, the session space is stored on the server side, and the ID of the open space is stored in the client's cookie. >>>More
This means to judge that the variable $entry is not equal to. And not equally. and the following is dir($dir.$entry) Yes. >>>More
According to the original ** on the book, it is as follows: >>>More
In fact, there are a lot of integrated installation packages that can put everything in place for you at once, but it is not recommended to do that. >>>More