PHP4 User manual: Process Control-require_php

Source: Internet
Author: User
Manual

TABLE border=0 cellpadding=0 cellspacing=0 height= "100%" width= "100%" >

Require ()
The Require () statement replaces itself with the file it specifies, which is much like the preprocessing # include feature in C.

If the "URL fopen wrappers" entry is open in PHP (this is the default configuration), you can use the URL instead of the local path in require (). For more information, see Remote Files and fopen ().

An important hint is: When a file is include () or require (), how to work, starting from the target file analysis of PHP modules and HTML modules, at the end of the summary PHP module.

The premise is that there are some executable PHP code that are effectively PHP start and end tags contained in the file.

Require () is not actually a PHP function: correctly speaking, it is a constituent part of a language. There are some differences between its rules and functions. For example, require () is not controlled by the containing control structure. In addition, it does not return any values; The result of attempting to read a return value from a require () call is to parse the error.

Unlike the include (), require () will always read the target file, even if it does not have an executable line. If you want to conditionally include a file, please use include (). Conditional statements do not affect require (). However, if the line on which the require () occurs was not executed, neither would any of the code in the target file be executed.

Similarly, loop control does not affect the behavior of require (). Although the include file is still controlled by loops, require () executes only once.

This means that you cannot put the require () statement in a looping statement, expecting it to contain different files in each iteration. To do this, use the Include () statement.


Require (' header.inc ');

When a file is contained by require (), the contained code inherits the scope of the variable that occurred require (). Any available variable in the calling file line will be available in the called file. If require () occurs in a function that is calling a file, then all the code in the called file appears to have been defined in the function.

If require () contains files that are opened by HTTP using fopen, if the target server can parse the target file as PHP code, the variable can be passed with a URL with an HTTP GET request string of require (). Strictly speaking require () a file and the variable scope that inherits its parent file are different: The script is actually running on the remote server, and the local script contains its results.


/* This person example assumes that Someserver has already configured. PHP parsing instead of. txt files.
* Similarly, ' works ' means that the variables contained in the file $varone and $vartwo are available */

/* Won ' t work; File.txt wasn ' t handled by Someserver. */
Require ("http://someserver/file.txt?varone=1&vartwo=2");

/* Won ' t work; Looks for a file named ' file.php?varone=1&vartwo=2 '
* On the local filesystem. */
Require ("file.php?varone=1&vartwo=2");

/* Works. */
Require ("http://someserver/file.php?varone=1&vartwo=2");

$varone = 1;
$vartwo = 2;
Require ("file.txt"); /* Works. */
Require ("file.php"); /* Works. */

In PHP 3, files that are require () may execute a return statement as long as the statement occurs within the global scope of the Require () file. Can not occur inside any block (curly braces). In PHP 4, this person's functionality has been stopped. If you need such a feature, see include ().

See also include (), require_once (), include_once (), ReadFile (), and virtual ().

  • 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.