On 03/22/2010 07:48 PM, Robert P. J. Day wrote:

   to recap regarding an earlier question i asked regarding extending
include paths, i have an existing project (call it "proj" currently
all under a top-level directory also named "proj") which can be SVN
checked out anywhere under a user's home directory.  so in my case, i
might have my svn working copy under, say,
/home/rpjday/stuff/work/proj/, and all proj-related content under

   at the moment, there are some subdirs under proj/ like "common" and
"utils" and "debug", and all includes or requires throughout the
working copy are currently and awkwardly of the form:

   include '../../proj/utils/somescript.php';

in short, every script that needs to include another one somewhere
else in the code structure sadly needs to know its precise relative

   my proposal is to get rid of most of that by:

1) having developers set a single env var PROJ_DIR in their login
    session, reflecting wherever the heck they checked out their
    working copy to, then ...
2) having said developers uniformly extend their directly callable PHP
    scripts with something at the very top like:

   set_include_path(getenv('PROJ_DIR') . PATH_SEPARATOR . get_include_path());

not only will that let them simplify their command-line callable
scripts to say just:

   include 'utils/somescript.php';

also, as i read it, that newly-extended include path percolates down
through all PHP scripts invoked directly or indirectly from this one,
right?  so while i could add that set_include_path() to every single
PHP script everywhere in the code base, it's really only necessary to
add it to those PHP scripts that people intend to *invoke* directly --
every other script will pick it up automatically as it's called, is
that correct?  (did i phrase that meaningfully?)

   that was part one.

   the new additional complication is that some of those PHP scripts
will manually construct HTTP POST requests and ship those requests off
to PHP scripts that live under a public_html/ directory, whose
scripts might *also* want to include some of those very same utils/ or
common/ scripts but that modified include path will, of course, not
carry across a POST request, so what's the standard way to similarly
modify the include path of the scripts on the server end?

   (unsurprisingly, all those "server-side" PHP scripts are also part
of the entire SVN checkout just so i can keep everything in the same
place for testing.)

   so how can i have those "server-side" scripts extend their search
path based on, perhaps, the same environment variable?



Robert P. J. Day                               Waterloo, Ontario, CANADA

             Linux Consulting, Training and Kernel Pedantry.

Web page:                                          http://crashcourse.ca
Twitter:                                       http://twitter.com/rpjday

What I do is, set the include path in the top-level bootstrapper.


set_include_path(dirname(__FILE__) . '/lib' . PATH_SEPARATOR . get_include_path());

Then I load the autoloader from /lib/autoload.php at the time of bootstrap.

/lib contains others /lib/Common, /lib/Util, etc.

So when I say "new Common_Form();", it will include /lib/Common/Form.php

Nilesh Govindarajan
Site & Server Administrator

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to