Let's say my document root dir is /root and in that directory I have my index.php, plus two subdirs called branch1 and branch 2. Both branch1 and branch2 have include files, one of which must be included based on one or more conditional statements. (And yes, I am aware of the inadvisability of having different versions of files under the same names, but that's something I'm willing to accept in this particular scenario.)
For (a simplified) example:
/root
/root/index.php
/root/branch1
/root/branch2/include.php
/root/branch2
/root/branch2/include.php
What I want to do is something like this:
if ($condition)
chdir ('branch1')
else
chdir ('branch2');
include ('./include.php');
Obviously the above code does not work, because even after a chdir() the include path is still relative to /root/index.php.
Is it possible (and if so, how) to change the base directory on which include(), require() and other operations involving relative paths will be based? (The idea here is, of course, not to just do the include in the above example, but a lot more.)
Of course someone will now point out that the proper way to do it is:
if ($condition)
include ('branch1/include.php')
else
include ('branch2/include.php')
but I'm deliberately looking for a kludge here. :-)