Jump to content

Difference Between Include_once() and require_once


Lakshmi

Recommended Posts

include() and require() are practically the same.There is only one difference, require() pastes the content and executes it, while include() only pastes, and executes if the calling script asks for it.For example:

$var = 1;if ($var == 2){ include_once("file.inc"); require_once("file2.inc"); }
In this code, only file2.inc will be inserted :) Because the condition is false, include() won't be executed, where require() will :)the _once() addition only tells the script should only insert the content once, and skip the next calling to that file when there is another call :(
Link to comment
Share on other sites

Hi, :) Or Refer Site"http://us2.php.net/manual/en/function.require-once.php"require_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. See the documentation for require() for more information on how this statement works. 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. For examples on using require_once() and include_once(), look at the PEAR code included in the latest PHP source code distributions. Vijay

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...