require_once with relative paths
Posted: Sat Apr 17, 2004 7:44 pm
I have separated my code into various directories, is the relative path taken from the current file i.e. the file the require_once statement resides, or from the very first php file that is used.
for instance I have a UserManager class which uses a User class, I also have a test php file which instantiates the UserManager in a different directory again (the filesystem structure is below!!!). From the command line (in the test directory) I call 'php testUserManager.php', I get the error message specified below.
The required file(s) from the UserManager class should be one directory up and then into the data directory for the User class and into the collection directory for the Vector class but this does not work.
The way I got it to work is by going up one directory then into the classes directory then finally into either the data or collection directory.
This to me seems wrong, it appears that the base from which the relative paths are working is from the test directory where my test code resides instead of being relative to where the class that is requiring the file.
Obviously my question is is this true and why???????
Filesystem Structure:
C:\
Program Files\
Apache Group\
Apache2\
htdocs\
test\
testUserManager.inc.php
classes\
authentication\
UserManager.inc.php
collection\
Vector.inc.php
data\
User.inc.php
[ERROR STATEMENT]
C:\Program Files\Apache Group\Apache2\htdocs\base>php testUserManager.php
PHP Warning: main(../User.inc.php) [http://www.php.net/function.main]: failed to create stream: No such file or directory in C:\Program Files\Apache Group\Apac
he2\htdocs\classes\authentication\UserManager.inc.php on line 4
PHP Fatal error: main() [http://www.php.net/function.main]: Failed opening required '../User.inc.php' (include_path='.;c:\php4\pear') in C:\Program Files\Apach
e Group\Apache2\htdocs\classes\authentication\UserManager.inc.php on line 4
[UserManager.inc.php FILE][/b]
for instance I have a UserManager class which uses a User class, I also have a test php file which instantiates the UserManager in a different directory again (the filesystem structure is below!!!). From the command line (in the test directory) I call 'php testUserManager.php', I get the error message specified below.
The required file(s) from the UserManager class should be one directory up and then into the data directory for the User class and into the collection directory for the Vector class but this does not work.
The way I got it to work is by going up one directory then into the classes directory then finally into either the data or collection directory.
This to me seems wrong, it appears that the base from which the relative paths are working is from the test directory where my test code resides instead of being relative to where the class that is requiring the file.
Obviously my question is is this true and why???????
Filesystem Structure:
C:\
Program Files\
Apache Group\
Apache2\
htdocs\
test\
testUserManager.inc.php
classes\
authentication\
UserManager.inc.php
collection\
Vector.inc.php
data\
User.inc.php
[ERROR STATEMENT]
C:\Program Files\Apache Group\Apache2\htdocs\base>php testUserManager.php
PHP Warning: main(../User.inc.php) [http://www.php.net/function.main]: failed to create stream: No such file or directory in C:\Program Files\Apache Group\Apac
he2\htdocs\classes\authentication\UserManager.inc.php on line 4
PHP Fatal error: main() [http://www.php.net/function.main]: Failed opening required '../User.inc.php' (include_path='.;c:\php4\pear') in C:\Program Files\Apach
e Group\Apache2\htdocs\classes\authentication\UserManager.inc.php on line 4
[UserManager.inc.php FILE]
Code: Select all
<?PHP
//require_once("../collection/Vector.inc.php"); // DOESN'T WORK....
//require_once("../User.inc.php"); // DOESN'T WORK....
require_once("../classes/collection/Vector.inc.php"); // WORKS....
require_once("../classes/data/User.inc.php"); // WORKS....
class UserManager {
}
?>