| Markus Albe 2005-09-21, 3:55 am |
| Hi everybody,
I'm new to the list and I haven't had time to check if this was already
discussed:
Why not make mandatory the use of "dirname(__FILE__)" prepended to
includes of other PEAR libraries?
Why? To avoid problems with dependencies on servers that don't have PEAR
installed or that don't have the PEAR path in the include path (I know
this can be easily added in a common file, but that makes PEAR libraries
that depend on other PEAR packages less "drop-in'ish", because it relays
on the assumption that the system where the package is to be used
already has a file common to all scripts... Also the .htaccess solution
isn't great, and it costs apache quite a few bytes of extra memory...:-\)
Let's take HTML_Page2 as an example, it depends on HTML_Common.
My dir structure looks like:
/var/www/project/bin /* where my scripts are located */
/var/www/project/lib/PEAR /* where I uploaded PEAR */
If the PEAR path is not set in the include path, and I include
HTML_Page2 from a script in the "bin" dir like
"include_once dirname(__FILE__).'/../lib/PEAR/HTML/Page2.php';"
PHP won't be able to find HTML/Common.php when HTML_Page2 tries to
include it like "require_once 'HTML/Common.php';".
If instead it required the file like
"require_once dirname(__FILE__).'../HTML/Common.php';" it won't fail...
Since file paths must match class names, it's not so hard to determine
the number of '..' needed, and it could be even automated somehow (I'm
sure we can come up with some simple method for it)
I know it may not look so refined as the current technique does, but so
far this is the only way to avoid having to append the PEAR path to the
include path; I only have to have properly include the lib I want and
that's all.
I haven't tested the performance of this, but I'm using it in all my
scripts and it doesn't seems to affect at all...(of course there's some
overhead, but probably PHP also has some overhead for resolving a
relative path agains the full path this technique provides)
Hope to hear from your nice community :)
Best regards,
Markus Albe
|