Page 1 of 1
Inlude Path
Posted: Thu Aug 31, 2006 1:20 pm
by ndnow
I was just wondering how to handle the include path properly within a code library. I am writing a library
to use on all my programs that will handle database usage, session handling and whatever else I will need.
I've been fighting in my mind over how to handle the include path with PHP and have come to no conclusion
that I like.
I was wondering which approach I should take. For instance I will have a child class that will include the parent
class within the child class but can be instantiated from anywhere in the program. The only sound solution I
can find is to set the include path on the server but I dont necessarily like this idea because not all servers
will allow for this. Are their any suggestions you guys have on this subject or am I just stuck setting the include
path?
Posted: Thu Aug 31, 2006 1:24 pm
by Luke
well you can set the include path like this of course:
Code: Select all
set_include_path(get_include_path() . PATH_SEPARATOR . YOUR_PATH_HERE);
But I would look into something like a service locator...
viewtopic.php?t=51794&highlight=service+locator
viewtopic.php?t=51873&highlight=service+locator
Another thing to look at (if php5) is __autoload:
viewtopic.php?t=52943&highlight=autoload
Posted: Thu Aug 31, 2006 1:34 pm
by ndnow
yeah those are the kind of idea's I was looking for I really dont want to set the include path I would like to stray from that. Thanks a lot for the links
much much appreciated.
Posted: Thu Aug 31, 2006 1:42 pm
by Luke
what's the problem with setting the include path?
Posted: Thu Aug 31, 2006 1:59 pm
by ndnow
From my programming perspective it just doesn't seem very organized having to set something before use. But Im weighing all my options
and will most likely use it in the end but would like to know what options are out there and explore them.
Posted: Thu Aug 31, 2006 1:59 pm
by Luke
...?? that's what it's there for... ??

Posted: Thu Aug 31, 2006 4:57 pm
by Ollie Saunders
I don't really understand what thoughts are going through your mind ndnow but I'll tell you how I manage including in my library in the hope that it might be relevent to your problem.
Firstly its pretty much a given that a library will have to be installed in the include path. So what I have done is to put the bulk of my library code in a folder that is supposed to go in the include path with a couple of files outside of that the will go directly in the include path.
Code: Select all
include_path/OF.php
include_path/OF_Autoload.php
include_path/OF/*.php (loads of files)
This means that the user of my library can:
and forget about including completely or if they like:
Code: Select all
require_once 'OF.php';
function __autoload($class) {
if (OF::isDecendentClass($class)) {
OF::loadClass($class);
} else {
// any existing autoload code you had
}
}
..or load classes manually as they require...
Code: Select all
require_once 'OF.php';
// these are all equivalent
OF::loadClass('OF_Select');
OF::loadClass('Select');
require_once 'OF/Select.php';
Posted: Thu Aug 31, 2006 9:19 pm
by alex.barylski
ndnow wrote:From my programming perspective it just doesn't seem very organized having to set something before use. But Im weighing all my options
and will most likely use it in the end but would like to know what options are out there and explore them.
lol...
Programming is all about properly initilizing something before using it...
Even in OOP a ctor() is called before using an object
Why would that seem impractical?
Posted: Fri Sep 01, 2006 10:22 am
by ndnow
ole wrote:I don't really understand what thoughts are going through your mind ndnow but I'll tell you how I manage including in my library in the hope that it might be relevent to your problem.
Firstly its pretty much a given that a library will have to be installed in the include path. So what I have done is to put the bulk of my library code in a folder that is supposed to go in the include path with a couple of files outside of that the will go directly in the include path.
Code: Select all
include_path/OF.php
include_path/OF_Autoload.php
include_path/OF/*.php (loads of files)
This means that the user of my library can:
and forget about including completely or if they like:
Code: Select all
require_once 'OF.php';
function __autoload($class) {
if (OF::isDecendentClass($class)) {
OF::loadClass($class);
} else {
// any existing autoload code you had
}
}
..or load classes manually as they require...
Code: Select all
require_once 'OF.php';
// these are all equivalent
OF::loadClass('OF_Select');
OF::loadClass('Select');
require_once 'OF/Select.php';
Thanks Ole that is very helpfull.