Friday, April 3, 2015

What are the differences between require and include, include_once and require_once?

The include() statement includes and evaluates the specified file.The documentation below also applies to require()
The two constructs are identical in every way except how they handlefailure.include() produces a Warning while require() results in a Fatal Error. In other words, use require()if you want a missingfile to halt processing of the page.
include() does not behave this way, the script will continue regardless.

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 differencebeing 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 particularexecution 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.

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.

No comments:

Post a Comment