include_path

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

include_path

Post by guitarlvr »

my include_path in php.ini is set to include the PEAR directory which i imagine is pretty standard. My question is, what exactly does it do? how do i include classes that are inside the PEAR directory in my .php pages?
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

You can directly

Code: Select all

include 'DB.php'
instead of

Code: Select all

include '/path/to/pear/DB.php';
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

That's pretty sweet. is that where most developers put libraries such as swiftmailer, template lite, html purifier, etc?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

I prefer not to rely on anything that's set in php.ini because not every php.ini is the same. I specify the path an file in relation to the current file using dirname(__FILE__) for every file that I include.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

set_include_path() and get_include_path() may be of interest.
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

guitarlvr wrote:That's pretty sweet. is that where most developers put libraries such as swiftmailer, template lite, html purifier, etc?
But if you have multiple include paths and for some reason there are files with same names i wonder which one will be included :)
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

guitarlvr wrote:That's pretty sweet. is that where most developers put libraries such as swiftmailer, template lite, html purifier, etc?
I don't know.. I've never checked. Swiftmailer is so well put together, I get lost in amazement every time that I read the code. HTML Purifier is a lot easier to follow, but I'm a bit more familiar with HTML and lexers than anything e-mail related.

I hope they did, though. I've ran into problems where PHP isn't exactly sure which folder I'm referring to without the absolute path of __FILE__.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

miro_igov wrote: But if you have multiple include paths and for some reason there are files with same names i wonder which one will be included :)
The answer is pretty simple: the first one it finds. (this and the order of searching is somewhere in the documentation, but i can't find it right now)

(Aha, i found it: http://be2.php.net/manual/en/function.include.php)
Files for including are first looked in include_path relative to the current working directory and then in the directory of the current script. E.g. if your include_path is libraries, current working directory is /www/, you included include/a.php and there is include "b.php" in that file, b.php is first looked in /www/libraries/ and then in /www/include/. If filename begins with ./ or ../, it is looked only in include_path relative to the current working directory.
Post Reply