Include files
require()
include()
require_once()
include_once()
There are 2 basic functions in PHP to include file; require()
and
include(). These 2 functions are almost identical
to each other.
require_once() and include_once()
just another strict way for require()
and include(), which guarantees include files
for once.
require() include()
The require() statement
includes and evaluates the specific file.
require() includes
and evaluates a specific file. Detailed information on how this
inclusion works is described in the documentation for include().
require() and include() are identical
in every way except how they handle failure. include() produces a Warning while require() results in a Fatal Error. In other words,
don't hesitate to use require() if you want a missing file to halt processing
of the page. include() does
not behave this way, the script will continue regardless.
<?php
require 'prepend.php';
require $somefile;
require ('somefile.txt');
?>
require_once() & include_once()
The require_once() statement includes and evaluates the specified
file during the execution of the script.
This is a behavior
similar to the require() statement, with the
only difference being that if the code from a file has already
been included, it will not be included again.
require_once() should be used in cases where the same file might
be included and evaluated more than once during a particular execution
of a script, and you want to be sure that it is included exactly
once to avoid problems with function redefinitions, variable value
reassignments, etc.
The include_once() statement includes and evaluates the specified
file during the execution of the script. This is a behavior similar
to the include() statement,
with the only difference being that if the code from a file has
already been included, it will not be included again. As the name
suggests, it will be included just once.
include_once() should
be used in cases where the same file might be included and evaluated
more than once during a particular execution of a script, and you
want to be sure that it is included exactly once to avoid problems
with function redefinitions, variable value reassignments, etc.
|