What's the difference (require, include, include_once, require_once)?

Gamma Spamma
Decennium
Joined
Dec 16, 2011
Messages
2,009
Reaction score
640
Well the title says it all...

What exactly is the difference between:
include();
require();
include_once();
require_once();

Or are they all exactly the same.. It's just I'm coding some little scripts and I want to make sure I'm including pages right! (The pages I am including/requiring are pages like config's, class.core etc..)

ALSO, my other question is; If a page I'm requiring has a require inside it that the page that I am requiring on requires the page..
For example;

My index.php page is requiring class.core.php, which in the class page also includes config.php, which is also required by index.. So will I need to also include/require the config in the index page or will the config load with the class.core so that I don't need to re-require it?
 
include - tries to include the file and echo an error, when not found
require - tries to include the file and echo an error + abort the whole script when not found
*_once - cannot include a specific file another time

The safest is require or require_once (depends on you want to re-include a file or not).
 
Back