Page 1 of 1
A curiousity regarding include vs. include_once
Posted: Fri Jul 27, 2007 1:32 pm
by ReverendDexter
It seems to me that for "good, clean code", you would *always* want to use a xxxxx_once() function.
Is there any reason why you would prefer to use include (or require) instead of include_once (or require_once)? Is there less overhead, or would there be a reason to inlcude/require something multiple times?
Posted: Fri Jul 27, 2007 2:31 pm
by Ambush Commander
In procedural programming, using an "include" essentially inlines the code you want into the PHP document. Using functions, however, should make this unnecessary, and this sort of system can get very messy if not done with discipline.
There is less overhead for just include/require versus include_once/require_once, however, it is usually quite negligible.
Posted: Fri Jul 27, 2007 2:54 pm
by superdezign
I always use include_once, because I set up every file to be able to work independently, so they need to each be able to include the necessary files. However, since a lot of those overlap, include_once helps out.
The alternative to it would be how C++ header files are handled by giving each one a unique definition and checking if it is defined(). As long as include_once is available, I'll chose that method over the C way.
Posted: Fri Jul 27, 2007 3:03 pm
by Luke
I <3 namespaces...
Code: Select all
from mylib.forms import myform
import mylib.settings
def someFunc():
print myform(settings.form)