Hi,
This is a problem I encountered a while ago, and I worked around it at the time but that workaround now has landed me with a bigger problem 🙁
What I wanted was a one-liner that I could put at the top of all pages on a site, which are arranged in different directories. This was chiefly for the purpose of portability, so all my require() calls (used by the __autoload function for my classes etc.) could use 'absolute' paths relative to the document root, making it easy to deploy on other servers. (The problem is sorta recursive, because it also hindered the writing of the function itself).
The problem was, the '.' in the generic include_path only lets you include from the same directory as the executing script. I did learn that it's possible to use set_include_path(), but then you have to either: call set_include_path() in the autoload include and copy it into every single directory; or call set_include_path() before the require() call on every page. Neither really ideal!
I solved this for that first site by simply adding the document root to the include_path of each machine. However, now I'm looking to write another project on the same server, I have the problem that my classes from the original one would also be searched, and some of these are of the same name but different contents, which would break all sorts of things 🙁
I was never that happy with the php.ini editing workaround anyway, as it'd have to be done on every target machine and on managed hosting might not be allowed.
Is there a better solution to defining an "site-absolute" include-path in one line, that'd be the same in each script? The most concise I can find is:
set_include_path(get_include_path() . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT']);
require_once('includes/classAutoLoad.inc');
I would prefer to get it down to just one line, but it seems a chicken-and-egg problem. Is there a way?
Thanks in advance and sorry if I rambled a bit.