Difference PHP include () and require () method: turn

Original link: http://www.cnblogs.com/guoyongrong/p/3685244.html

Article from: http: //developer.51cto.com/art/200909/153687.htm

 

This article summarizes the PHP include () and require () the difference of the two methods include external files at. Basically, the approach failed to load, different properties, and elastic aspect.

AD:  51CTO College: IT Courses Online Look!

 

PHP's include () and require () are two external file that contains the method, what is the difference for both methods, many beginners may not understand. The following summarize the PHP include () and require () the difference:

1: The different treatment that failed to load:

include () will generate a warning, and require () results in a Fatal Error (an error, the script stops execution)

require ():. If the file does not exist, it will report a fatal error the script to stop execution

include (): if the file does not exist, will give a warning, but the script will continue execution

Here we should note in particular: use include () when the file does not exist, the script continues, this situation before only in PHP 4.3.5

Recommended use require_once () and include_once (), can detect whether there are duplicate file contains.

2.php performance

To include (), in include () is executed every time a file is read and assessment;

For require (), the file is only processed once (in fact, replace the contents of the file require () statement).

This means that if you have one of these contains code and instructions may execute the code several times, use require () more efficient.

On the other hand, a different phase of the read file when executed each time the code, or have a set of files by the iterative loop, use include (),

Because they can give the file name you want to include a variable set, use this variable when parameters include ().

3. The two ways to provide different elastic.

require the use of methods such as require ( "./ inc.php");. PHP programs are usually placed in the front, PHP scripts before execution, it will first read the files require the introduction of the specified, it becomes a part of PHP web programming.

include the use of methods such as include ( "./ inc / .php" );. It is generally placed in the processing section of the flow control. PHP program pages when reading include files, just read it in. In this way, the process can be simplified when the program execution.

require even when conditions will also be included in the FALSE position, and to include only the execution time will change the position to do it.

require_once () statement includes and evaluates the specified file during script execution. This behavior and require () statement is similar, the only difference being that if the code from a file has already been included, it will not be included again. require_once () function returns and require () is almost the same

include_once () statement includes and evaluates the specified file during script execution. This behavior is similar and include () statement, the only difference being that if the code from a file has already been included, it will not be included again. include_once () function returns and include () are almost identical

Require_once role is to be checked whether before loading the file, if not loaded then the load if the load had not re-loaded, such as a type of a file defines the file is loaded twice if an error occurs

These are the difference PHP include () and require () method.

Reproduced in: https: //www.cnblogs.com/guoyongrong/p/3685244.html

Guess you like

Origin blog.csdn.net/weixin_30294709/article/details/94794651