A question about php include path

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
WilliamLou
Forum Newbie
Posts: 12
Joined: Fri Mar 14, 2008 1:32 pm

A question about php include path

Post by WilliamLou »

Hi there:
I want to know if the "include_path" really works or not in php.ini, it seems like php won't find files under this directory.
For example: I made a tar for php files. If it's extracted, the main directory will be ./main, and it contains two sub folders, ./main/daemon, ./main/class/. Users could extract the tar file to any directories like /tmp, and then if we modify the include_path in php.ini as the following:
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
include_path = ".:/php/includes:/tmp/main/"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
in my code, a.php under the subfolder daemon, I have some require statements like: require("class/b.php") . If the current path is /tmp/main, then in command line, php a.php will run without any problems; however, in any other directories, for example: under /tmp/main/daemon, php. a.php won't work, it always have some strange error messages in php.err. I doubts php will just look for files under the current working directory, not all the directories under include_path, is that right? Thanks!
WilliamLou
Forum Newbie
Posts: 12
Joined: Fri Mar 14, 2008 1:32 pm

Re: A question about php include path

Post by WilliamLou »

any suggestions?!
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: A question about php include path

Post by Burrito »

PHP will look for relative files in whatever location the file is currently in and whatever you include in the includes directive in php.ini.
Post Reply