Home  >  Article  >  Backend Development  >  Detailed explanation of file inclusion in php

Detailed explanation of file inclusion in php

小云云
小云云Original
2018-03-21 10:32:322423browse

In PHP, file inclusion may be needed in many places. The so-called file inclusion (loading) in PHP means: separating part of the code (often used) and placing it in a separate file; introducing the corresponding file on the required page. This article mainly shares with you the detailed explanation of file inclusion in php, I hope it can help you.

PHP code execution process:

1. Read the code file

2. Compile (convert to binary information, generate opcode)

3.zendEngine Parse Opcode and perform operations

4. Return the execution results in HTML form.

It should be noted that the imported files are compiled separately; if there are errors in the imported files, the prompt will only be prompted when the execution reaches this point, and the previous code will be executed normally. (Differences from overall compilation). In addition, when calling a function declared in the imported file, the principle of function calling is to declare it first and then call it. If the declaration and call are in the same file, the call can be placed before the declaration position; if the declaration is in a separate file, it must be loaded first, otherwise there will be no corresponding function in the current code segment, which will cause a running error.

About the difference between include and require:

If include fails to introduce a file, a warning is returned, and subsequent code continues to execute

If require fails to introduce a file, a fatal error is returned, and subsequent code does not Execution

The imported file must be used by subsequent code. When the file loading fails, the execution of the code needs to be terminated. It is recommended to use require.

_once function:

For already Loading files can avoid repeated loading of code and repeated definition of functions.

Related recommendations:

PHP file contains detailed description

php fake local file contains vulnerable code

php file contains relevant questions

The above is the detailed content of Detailed explanation of file inclusion in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn