PHP specifying a fixed include source for scripts in different directories

Posted by Extrakun on Stack Overflow See other posts from Stack Overflow or by Extrakun
Published on 2010-06-12T07:34:33Z Indexed on 2010/06/12 7:42 UTC
Read the original article Hit count: 250

Filed under:
|

I am currently doing unit testing, and use folders to organize my test cases. All cases pertaining to managing of user accounts, for example, go under \tests\accounts. Over time, there are more test cases, and I begin to seperate the cases by types, such as \tests\accounts\create, \tests\account\update and etc.

However, one annoying problem is I have to specify the path to a set of common includes. I have to use includes like this:

include_once ("../../../../autoload.php");
include_once ("../../../../init.php");

A test case in tests\accounts\ would require change to the include (one less directory level down). Is there anyway to have them somehow locating my two common includes? I understand I could set include paths within my PHP's configurations, or use server environment variables, but I would like to avoid such solutions as they make the application less portable and coupled with another layer which the programmer can't control (some web-host doesn't allow configuration of PHP's configuration settings, for example)

© Stack Overflow or respective owner

Related posts about php

Related posts about php5