Php file several ways of introducing the difference

Applications include statement references

Note: When using an external application include file, only code execution to include the statement, external file will be introduced and read, when the external file referenced error occurs, the system gives only a warning, and then continue to the entire php file under execution.

Applications require statement references a file

Before php file is executed, the parser replaces require php statement with the entire contents of the referenced file, and then with other statements other than statements require new php file and press the new php file program code.

NOTE: Because require statement is equivalent to the contents of another file is completely copied to the source file, which is generally in the source file starting position for the common files and the common functions required class files reference the like.

The difference between statements and include statements require

When using require statement to invoke a file, if the call is not found, the statement will require output an error message and immediately terminate the script process. And include statements in the file is not found it will output a warning not to terminate the processing of the script.

When using require statement calling the file, as long as the implementation of a program, it will call an external file at once; and calling external files include statements only when program execution to the statement, will call an external file.

Include_once statement refers to the application file

Application include_once statement before importing the file check to make sure that the file had been applied in other parts of the page, if there is, it will not be repeated references to the file, the program can only be referenced once.

For example: the file you want to import some custom functions, so if this is repeated statement repeated import files in the same program, an error will occur in the second import, because the function does not allow the same name in PHP

Require_once statement refers to the application file

Extending require statement when require_once statement, its function and require statement substantially similar, except that, at the time of application require_once statement will first check the file you want to reference is not have been cited in the program elsewhere, if there is , the call will not repeat the file.

For example: require_once statement refers to the simultaneous application of two of the same file on the same page, then in the output, only the first file is executed, the second referenced file will not be executed.

The difference between using require_once and include_once statements

include_once statement calls an external file during script execution when an error occurs, a warning is generated, and require_once statement that led to a fatal error.

Purpose is to ensure an included file can only be included once, use these two statements can prevent accidental contains the same library, resulting in repeat-defined functions and generates an error.

Guess you like

Origin www.cnblogs.com/mo3408/p/12652439.html
Recommended