The require_once() statement replaces itself with the specified file, much like the C preprocessor's #include works, and in that respect is similar to the require() statement. The main difference is that in an inclusion chain, the use of require_once() will assure that the code is added to your script only once, and avoid clashes with variable values or function names that can happen.
For example, if you create the following 2 include files utils.inc and foolib.inc
GLOBALS ARE NICE this is requiring globals.inc again which is also required in foolib.inc Running goodTea: Oolong tea tastes good! Printing foo: Array ( [0] => 1 [1] => Array ( [0] => complex [1] => quaternion ) ) |
Also note that, analogous to the behavior of the #include of the C preprocessor, this statement acts at "compile time", e.g. when the script is parsed and before it is executed, and should not be used for parts of the script that need to be inserted dynamically during its execution. You should use include_once() or include() for that purpose.
For more examples on using require_once() and include_once(), look at the PEAR code included in the latest PHP source code distributions.
See also: require(), include(), include_once(), get_required_files(), get_included_files(), readfile(), and virtual().
HIVE: All information for read only. Please respect copyright! |