Home > Backend Development > PHP Tutorial > Comparison of PHP4 reference file statements_PHP tutorial

Comparison of PHP4 reference file statements_PHP tutorial

WBOY
Release: 2016-07-21 16:06:07
Original
802 people have browsed it

Comparison of PHP4 reference file statements
Ling Xin Yijian
When we program, there are some things that often need to be used repeatedly. It is really inefficient to enter them every time they are used. Therefore, there are statements in programming languages ​​that specifically handle these operations. We call them "reference file statements"! When needed, just use these reference statements to directly introduce the needed stuff, and the efficiency will be improved a lot at once, haha~~~
In PHP4 we can use require();include() ;require_once();include_once; These four reference statements directly reference existing files into the program. Reasonable use of them can provide a lot of efficiency. Of course, this can only be understood after understanding their direct similarities and differences. This article focuses on how to use them!

require() statement
Syntax: require("statement");

Parameters: "statement" is the name of the program segment file to be referenced.

Note: The require() statement will read the file referenced by require before the PHP program is executed, so require is usually placed at the beginning of the program. So be careful, the require statement is a bit strong, I mean, no matter whether the program really needs the referenced files, as long as you use the require statement, it will include them! Even if you use this function to include in a conditional control statement, even if the condition is not true, the referenced file will be included! Zombies are formed. These zombies will not have any visible effect during operation, but it will obviously increase the burden, so pay special attention to this! If an inclusion error occurs using the require statement, the program will output an error message and stop running! !


include() statement
Syntax: include("statement");

Parameters: "statement" is the name of the program segment file to be referenced.

Note: As you can see, the syntax of require() and include() is the same. But their functions are slightly different. The include statement only reads in the files to be included when it is executed. To facilitate error handling, use the include statement. If an include error occurs, the program will skip the include statement. Although the error message will be displayed, the program will continue to execute! ! (This is different from what some textbooks say, but please believe me or try it yourself! Trust your own judgment!!)


require_once() statement
Grammar :require_once("statement");

Explanation: It can be said to be an extension of require. Its functions and usage are similar, but the difference is that the require_once statement has a reference chain, which can ensure that the file is added to your program. Only once, and will avoid conflicts between variable values ​​and function names. ^_^


include_once() statement
Syntax: include_once("statement");

Description: Like the require_once statement, the include_once statement extends the function of include. During program execution, the specified file is included. If the program referenced from the file has been included previously, include_once() will not include it again. That is to say, the same file can only be referenced once! ! !
Something else you need to know. The referenced file will no longer inherit the original PHP delimiter "". If the referenced document contains PHP code, It is necessary to reuse the delimiter "" to mark PHP code. In PHP4, reference statements have certain features of functions, supporting return values ​​and program diversion, which are not available in PHP3! Let me emphasize: when referencing a file, the system does not execute this page separately, but introduces the code of this page into the main program to which it belongs.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/315472.htmlTechArticleComparison of PHP4 reference file statements Ling Xin Yijian When we program, there are some things that often need to be used repeatedly. It would be too inefficient to enter it every time you use it. ...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template