PHP4 User Manual: Process Control-require_PHP tutorial

Source: Internet
Author: User
PHP4 User Manual: Process Control-require. TABLEborder0cellPadding0cellSpacing0height100 % width100 % require () statement replaces itself with the file it specifies, which is similar to the preprocessing # include function in C. If TABLE border = 0 cellPadding = 0 cellSpacing = 0 height = "100%" width = "100%">
Require ()
The require () statement replaces itself with the specified file, which is similar to the preprocessing # include function in C.
If the "URL fopen wrappers" item in PHP is open (this is the default configuration), you can use the URL in require () to replace the local path. For more information, see Remote files and fopen ().
An important reminder is: how does a file work when it is included () or require ()? analyze the PHP module and the HTML module from the target file, reabstract the PHP module at the end.
The premise is that some executable PHP code that is effectively included in the PHP start and end labels is in the file.
Require () is actually not a PHP function: Correctly speaking, it is a component of a language. Its rules are somewhat different from those of functions. For example, require () is not controlled by the include control structure. In addition, it does not return any value; the result of trying to read a returned value from the require () call is a parsing error.
The difference is that include (), require () will always read the target file, even if it does not have executable lines. If you want to include a file with conditions, use include (). The condition statement does not affect require ().
However, if the line on which the require () occurs is not executed, neither will any of the code in the target file be executed.
Similarly, loop control does not affect require () behavior.
Although the contained files are still controlled cyclically, require () is executed only once.
This means that you cannot place the require () statement in a loop statement, expecting it to contain different files in each loop. To do this, use the include () statement.

Require ('header. Inc ');

When a file is contained by require (), the contained code will inherit the variable scope of the line where require () occurs. Any available variables in the called file line will be available in the called file. If require () occurs in a function in the calling file, all the code in the called file is as if it has been defined in the function.
If the file contained in require () is opened by using fopen over HTTP, if the target server can parse the target file as PHP code, variables can be transmitted using require () with an http get request string containing a URL. Strictly speaking, require () is different from the variable scope of the parent file that inherits it: this script actually runs on a remote server, the result is included in the local script.

/* This example assumes that someserverhas configured the. php file but not the. txt file.
* Similarly, 'works' means that the variables $ varone and $ vartwo in the included file are available */

Http://www.bkjia.com/PHPjc/629430.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/629430.htmlTechArticleTABLE border = 0 cellPadding = 0 cellSpacing = 0 height = 100% width = 100% require () statement replaces itself with the file it specifies, this is similar to the preprocessing # include function in C. If...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.