"Namespace polution" in includes
| From: | Sebastian Delmont | Date: | Thu, 17 Jan 2002 22:31:53 +0000 |
| Subject: | "Namespace polution" in includes | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-3969@lists.php.net to get a copy of this message | ||
One thing I really don't like about the existing PEAR standards is the way
it poludes the include path.
Please correct me if I'm wrong, since I don't have much experience using
PEAR.
Currently, PEAR uses an "installation dir" where it places all it's files
and directories (PHP's "lib" dir, for example), and assumes that directory
is included on the "include_path".
So, if I want to use the "DB" module, I have to do
require 'DB.php';
And if I want to use the "Mail/sendmail" module,
require 'Mail/sendmail.php';
But what happens if, for some reason, I already had an "Mail" directory on
my website, with a "sendmail.php" page inside it. And those files were
completely unrelated to PEAR... those are "regular pages", to say something.
Well, depending on my current include_path, I will not be able to use the
PEAR Mail/sendmail module. And the bigger PEAR gets, the worse this problem
becomes, since there will be many more filenames that can collide.
Currently, I have two choices to overcome this problem. Put PEAR as the
first item on my include_path, but this means I can't include my own files
if they collide with PEAR names. Or I can put PEAR as the last item on my
include_path, but if I pick the wrong name for my files, then I can't use
some PEAR modules.
Either case means I have to be careful about how I name my files and
directories. But even then I can get in trouble if I get a new PEAR module,
or upgrade PHP, since it can contain newer files I didn't take into account
when creating my site.
Simply put, placing all PEAR files directly "on the top" of the include_path
is a big mistake.
I see two solutions that can even be used in parallel:
- place PEAR inside a directory so includes would look like
require 'PEAR/HTTP/Compress.php';
- Add some specialized mechanism to PHP for PEAR includes like:
require_pear 'HTTP/Compress.php';
or
require <HTTP/Compress.php>;
or
require 'pear:HTTP/Compress.php';
Again, I'm coming late to PEAR, and this might have been discussed before.
But unless I'm terribly wrong, this is a serious issue that has to be
solved.
Right now, I can't use PEAR directly because of this problem. I have
resorted to the "PEAR subdirectory" solution, and modified all modules that
I needed to use to use the "longer" include path.