include vs. include_once

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

include vs. include_once

Post by magicrobotmonkey »

Whats bad about always using include_once instead of include? The only thing I can think of is scoping issues.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I think it depends on the habits of the person. i.e. Are they include happy, or including libraries and functionality versus lazy/procedural.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

The only downside to using include_once() might be the slight overhead of the data and lookup.

If you have inlcude files that in turn include base library files, then include_once() allows you to put includes in every file as needed and not worry about multiple definitions.

On the flip side, if you don't want a file included twice then use include() and the offending code will produce an error.
Post Reply