Comparison of file statements referenced by php4 Ling Yijian in our programming, some things often need to be used repeatedly. If you input them once every time, it is too inefficient. Therefore, in programming languages, statements that specifically process these operations are called "reference file statements 』! When necessary, you only need to use these reference statements to directly introduce the required stuff, and the efficiency will increase a lot at once ~~~ In PHP4, we can use requ php4 to compare the referenced file statements.
Ling xinyijian
When programming, some things often need to be used repeatedly. if you enter them once every time, it is too inefficient. Therefore, in programming languages, statements that specifically process these operations are called "reference file statements 』! When necessary, you only need to use these reference statements to directly introduce the required stuff, and the efficiency will increase a lot at once ~~~
In PHP4, we can use require (); include (); require_once (); include_once; these four reference statements to directly reference existing files to the program. Reasonable use of them can provide a lot of efficiency. of course, this can be understood only after understanding their direct similarities and differences. This article focuses on their usage!
Require () statement
Syntax: require ("statement ");
Parameter: "statement" is the name of the program segment to be referenced.
Note: Before executing the PHP program, The require () statement reads the file referenced by require. therefore, require is usually placed at the beginning of the program. Therefore, pay special attention to the fact that the require statement is a bit strong. I mean, no matter whether the program really needs to reference the file or not, as long as you use the require statement, it will include them! Even if you use this function in a condition control statement to include, the referenced file will be contained even if the condition is not true! The formation of botnets does not have any visible effect during the running process, but it is obvious that it will increase the burden, so pay special attention to this! If an error occurs when you use the require statement, the program outputs the error message and stops running !!
Include () statement
Syntax: include ("statement ");
Parameter: "statement" is the name of the program segment to be referenced.
Note: The syntax of require () and include () is the same. However, their functions are somewhat different. The include statement reads the file to be included only when it is executed. Easy to handle errors. use the include statement. If an include error occurs, the program skips the include statement. Although the error message is displayed, the program continues to execute !! (This is different from some textbooks, but please trust me or try it on your own! Believe in your own judgment !!)
Require_once () statement
Syntax: require_once ("statement ");
Note: 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 files are added to your program only once, it also avoids conflicts between variable values and function names. Pai_^
Include_once () statement
Syntax: include_once ("statement ");
Note: like the require_once statement, the include_once statement extends the include function. During program execution, the specified file is included. if the program referenced from the file has previously been included, include_once () will not include it again. That is, you can only reference the same file once !!!
In addition, some things that you need to know will no longer inherit the original PHP delimiter" ", If the referenced document contains PHP code, you need to re-use the delimiter" Mark PHP code. The reference statement in PHP4 has some features of the function and supports the return value and program redirection. these are not included in PHP3! Emphasize that the reference file is not executed by the system alone, but the code of this page is introduced into the main program.