Re: Re: __autoload vs. spl_autoload_register
| From: | David Coallier | Date: | Thu, 06 Sep 2007 23:35:32 +0000 |
| Subject: | Re: Re: __autoload vs. spl_autoload_register | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-47936@lists.php.net to get a copy of this message | ||
On 9/6/07, Gregory Beaver <greg@chiaraquartet.net> wrote:
> Evert | Rooftop wrote:
> > Hi List,
> >
> > I'm looking at the the pear autoloader in SVN
> >
> > (http://svn.pear.php.net/wsvn/PEARSVN/Pyrus/trunk/src/Autoload.php?op=file&rev=0&sc=0)
> >
> >
> > Wouldn't it make more sense to make use of spl_autoload_register
> > instead? AFAIK this is a better practice because it allows multiple
> > autoload handlers (for different libraries/directory schemes) possible.
> >
> > The normal __autoload also pollutes the global namespace, whereas
> > spl_autoload_register does not. It is possible to provide a fallback, like:
> >
> > if (function_exists('__autoload'))
> > spl_autoload_register('__autoload');
> >
> > The only drawback is that it is possible to disable the SPL library
> > during PHP compilation, but I don't think any sensible person would do
> > this and I'd say its fairly safe to have SPL as a dependency for PEAR.
>
> Hi Evert,
>
> Actually, I know several sensible people who do that. Eccentric, but
> sensible :).
>
> Normally I would agree with this whole-heartedly, and I am leaning
> towards what you suggest, but it also adds complexity to a solution that
> is designed only for absolute beginners/lazy people.
>
> What might be an acceptable solution is:
>
> if (function_exists('spl_autoload_register')) {
> spl_autoload_register('PEAR2_Autoload');
> return;
> }
> if (!function_exists('__autoload')) ....
>
> What do you think?
>
> Greg
>
> --
> PEAR Development Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Are you reading my files ? I am usually eccentric enough to do such
thing. Paranoid ? Maybe. Safe ? Surely.
--
David Coallier,
Founder & Software Architect,
Agora Production (http://agoraproduction.com)
51.42.06.70.18