Re: PEAR / include path
| From: | Brent Cook | Date: | Tue, 08 Oct 2002 02:33:04 +0000 |
| Subject: | Re: PEAR / include path | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-2457@lists.php.net to get a copy of this message | ||
On Mon, 7 Oct 2002 zaphod@s4r.de wrote:
> [This followup was posted to php.pear.general and a copy was sent to the
> cited author.]
>
> In article <Pine.LNX.4.44.0210050954280.9111-100000@stampy.hauschen>,
> busterb@mail.utexas.edu says...
>
> > PEAR is designed to be integrated into PHP. As such, it must be easily
> > installed as a set of system-wide libraries, with no internal dependencies
> > on anything being installed at an absolute location. This same design
> > allows you to simply code:
> >
> > include 'PEAR.php';
>
> OK, that was clear to me. The problem is, you do it in a way, that there
> cannot be another system-wide library beside PEAR. The names of the
> files in the main directory are so simple, that it is to be expected
> that they might clash with other system-wide libraries.
OK, I see your point. If I might summarize, if you have your own library,
which happens to be called 'PEAR.php', 'DB.php' or anything already in the
pear system, that these names will conflict.
Personally, I place project-specific libraries in a folder called 'local'.
Then, I set the path to include_path to include PEAR and the base
directory. When I want to use PEAR's 'DB.php', I still say:
include 'DB.php';
But if I want to use a hypothetical local version of DB.php and not have a
conflict, I say
include 'local/DB.php';
Of course, there is the instance where you want to include a file in the
current directory with the same name as a PEAR top-level file. Just do:
include './DB.php'
I feel that these solutions still might not meet your needs though, so
read on.
> Since it is to be expected, that PEAR is still growing and that other
> new files will appear in the PEAR-directory, how will I know, that only
> updating PHP/PEAR w'ont crash my system, which depends on other
> system-wide libraries too.
I don't think PEAR is capable of 'crashing' a system, using the common
definition of crashing. Granted, APIs do change occasionally, but one
probably should not blindly update software without examining what has
changed first.
> You cannot expect other developers of system-wide libraries to behave
> more co-operative, if the developers of the most important PHP-library
> don't do it.
>
> include 'PEAR/PEAR.php';
Here is the unix shell command to automatically edit the pear libraries to
include PEAR relative to a PEAR directory instead.
for j in "require require_once include include_once"; do
for i in
find . -name "*.php"; do
sed "s/$j '/$j 'PEAR\//" $i>$i.tmp;
mv $i.tmp $i;
done
done
Just run this in the root directory of PEAR. Be sure to adjust the PHP's
include_dir accordingly.
> would not be much more complicated, but solve most of the problem.
Problem solved ;) The only issue here is that once you have edited the
files, you probably need to unedit them before upgrading anything (change
the replacement order for sed) with the pear(.bat) utility. I assume that
you use windows, so installing cygwin will be necessary using the method
above. There may be other ways of automating file editing in windows; I
don't know.
> I am not surprised, that this issue rises up again and again, because
> the way you deal with the include-path is an error in your design or at
> least very short-sighted.
Problems are best solved through solutions, and your criticism is taken
well. If this is still not what you had in mind, let me know and we can
work out something else.
- Brent