Click to See Complete Forum and Search --> : include vs. require


comptech520
09-15-2008, 07:47 AM
stupid question!

Whats the difference between include and require, I sort of know but I was hoping someone could fill me in.

NogDog
09-15-2008, 07:55 AM
The 3rd paragraph of the require() manual page (http://www.php.net/manual/en/function.require.php) spells it out pretty clearly, I think:
require() and include() are identical in every way except how they handle failure. They both produce a Warning, but 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.

ayvegh
09-15-2008, 08:20 PM
As a rule, unless the file isn't critical to the script outputting or acting correctly (not sure how it wouldn't but let's say what if ;)), you should be using require().

Also, keep in mind that if you think you may have a include/require collision (if there is a possibility that through an inclusion you will re-include a file), you can use include_once() or require_once() to have the same effect as the regular functions, but with the file only being included once during the entire execution of the script.

Hope this helps,
ayvegh