I see none of those problems you mentioned being caused by appending a
include path.
I only see namespace conflict between libraries, which is not a
problem of appending the include path, but conflicts in namespace and
scope. If your application stops working because you conflict with the
naming of the libraries you use, you should change your names and
don't blame the library that you want to include unless that library
obviously pollutes the global namespace.
In the general programming world (JAVA, C++,Python,..this list is
long, i code in many... damn even ashamedly Flash AS3) most of these
problems are solved by using name mangling in qualified namespaces.
Conceptually, a qualified name is represented as a namespace-URI/local-
part pair.
For Smarty this would look something like (PHP 5.3.0+ style):
namespace net\smarty\SuperCoolTemplateEngine;
Where the namespace URI comes from the domain name of
smarty.net (the
makers of the library) and the local-part is the library name, here I
have used "SuperCoolTemplateEngine" as the local-part but it can be
whatever you like, the URI part is *sacred* though, you should-not/
cannot change this. You would then create a library directory
structure that matches the namespace.
For the example:
net/
smarty/
SuperCoolTemplateEngine/
BTW I am not inventing this structure, it is used by other languages
as well, even though it is not a language specification of any of them
but a programming paradigm. Just google "qualified namespaces". It is
not surprising that PHP5.3 resolves this directory structure natively
in the spl_autload function, it is the long *over-due* past.
However, even *without* the PHP5.3 namespace keyword you can *still*
use these directory names anyway to construct your library paths and
the qualified namespace system still works perfectly.
Yes it is true that PHP has not had a *implicit* namespace capability
until now, though if you are building libraries there is nothing
stopping you from adhering to a namespace methodology. You can just
see the efforts of Zend and PEAR as systems for dealing with this in
PHP, though admittedly not as nice as true fully qualified names. In
fact you even do it in Smarty, though the methodology is also ad-hoc
and inconsistent with everybody else.
I really hope that PHP developers take a leaf from the others in using
*qualified* namespaces. Why the other guys can do it so easily and the
PHP coders can't is NOT a mystery, it is caused by perpetuating myth,
not co-operating with each other and having no f*$king idea in general
(excuse my Australian, yes i am, don't worry, i have a license from
birth for using the F word. lol. :-P). The funny thing is you can
still implement qualified namespaces today *without* PHP 5.3.0+ and it
solves all those problems.
Of course you may have exceptions, all the *broken* libraries in your
include path that you have until now been coping with, and I agree you
have to be conscious of what is in your include path, by removing
anything that is trying to *overtake* your environment.
This is as easy to fix as:
1) Take the broken library out of the include path.
2) Put it in it's own folder out of harms way. (maybe name it based
upon URI for consistency)
3) Reference it directly if you need it.
There is also a not so immediate but eventual step 4.
4) Point out that it's broken and try and get it fixed for the future.
I don't believe that the Smarty project should concern itself with
support for developers who have namespace problems OR broken libraries
of other projects. That is like if somebody would ask "should I use
print or echo?" that is a problem probably more related to the PHP
project and learning programming in general, and not to any specific
PHP project. This is not Smarty's support problem in relation to it's
templating engine, and looking back through the Smarty community
forums this is generally not the case anyway.
I think it is more important that Smarty concentrates on implementing
proven standards, and building a really awesome, super fast, user
friendly template engine, in that order of priority. (The *awesome*
part you already have and for that I really tip my hat off to
everybody. Great work! Amazing effort.)
Correctly using a namespace is a programming paradigm. It has nothing
to do with if we are allowed to append include paths or whether or not
their exists a *namespace* keyword in PHP. This type of thinking is
complete and utter myth.
I think the attitude of taking the path of least resistance is also
not helping the situation, in fact, it is just making it worse. You
have the opportunity *now* to correct it for the not so distant
future, "grab it by the horns" I say.
On Nov 9, 9:56 pm, Monte Ohrt <
mo...@ohrt.com> wrote:
> So you may know this guy, Andrei Zmievski. He is a long-time PHP core
> developer, and also a collegue of mine. I threw him the question "What are
> your general thoughts about 3rd party libraries adjusting the php
> include_path?" (I didn't mention Smarty or autoloaders.)
>
> His response:
>
> "I'm generally not a fan of that. Users have to be conscious of what's in
> their include path, especially in a production env"
>
> This supplements my thoughts about Smarty adjusting the include_path. As it
> stands Smarty will supply the option of the spl_autoloader, but will not be
> enabled by default.
>
> Monte
>
>
>
> On Mon, Nov 9, 2009 at 2:37 PM, Monte Ohrt <
mo...@ohrt.com> wrote:
> > What the include_path? There could easily be similarly named
> > classes/methods spanning separate folders, and developers organize their
> > include paths in the order they want them traversed. Many developers use the
> > include_path heirarchy to organize how class files get loaded. Name spaces
> > should elude this situation, but sadly php 5.3 is far from main stream. Also
> > depending on how the include_path is changed, this could create many new
> > (unnecessary) stat() calls for each included file, which is probably not
> > desirable.
>
> > Anyways, you now have the option to enable the spl_autoloader.
>