-- till <[EMAIL PROTECTED]> wrote
(on Friday, 07 November 2008, 05:47 PM +0100):
> On Fri, Nov 7, 2008 at 5:42 PM, Matthew Weier O'Phinney
> <[EMAIL PROTECTED]> wrote:
> > -- till <[EMAIL PROTECTED]> wrote
> > (on Friday, 07 November 2008, 03:40 PM +0100):
> >> On Fri, Nov 7, 2008 at 1:09 PM, Matthew Weier O'Phinney
> >> <[EMAIL PROTECTED]> wrote:
> >> > -- Michael Depetrillo <[EMAIL PROTECTED]> wrote
> >> > (on Thursday, 06 November 2008, 09:33 PM -0800):
> >> >> Does using autoload improve or reduce performance?
> >> >>
> >> >> I thought I saw an email by you where you stated in did.
> >> >
> >> > It improves performance, particularly when you strip out the
> >> > require_once calls within Zend Framework (which you can do with a simple
> >> > one-liner using find and sed).
> >>
> >> Just to add to this.
> >>
> >> Yes, and also no. Zend_Loader by itself is faster than all the
> >> require_once in the framework. However, it can be simplified still to
> >> e.g. using include vs. include_once since autoload is only invoked
> >> when the class is not found thus making include_once redundant.
> >
> > The main reason Zend_Loader uses include_once over include is to ensure
> > that if there are any arbitrary require_once or include_once calls
> > elsewhere in the codebase, they won't lead to a conflict. While you may
> > have stripped them from your Zend Framework install, we cannot assume
> > you've done the same in your userland code.
> 
> True, and true.
> 
> Did you ever consider benchmarking it against:
> 
> if (!class_exists($foo)) {
> include $foo;
> }
> 
> I haven't, so I am asking. I was thinking if a lookup in userland can
> actually outperform all the PHP-goodness. ;-)

Actually... loadClass() already does that. The issue is in the userland
code -- if they do a require_once or include_once in userland *after*
we've already loaded the class in the autoloader using simply include,
that will trigger the error. That's what I was getting at. That said,
we may be being to defensive about this.

> Also, the thing is, if you recommend that people use Zend_Loader in
> __autoload(), then using include instead of include_once is somewhat a
> given since __autoload would never invoke the loader if the class
> hasn't been loaded already. Right?
> 
> I know that inside the framework code, there are a ton of instances
> where Zend_Loader::loadClass() is used to load adapters/drivers etc..
> 
> I wish there was a way to register a default loader for the entire
> framework, so I could use mine everywhere. No idea if that is so hard
> to implement.

Zend_Loader::registerAutoload() registers with spl_autoload.

-- 
Matthew Weier O'Phinney
Software Architect       | [EMAIL PROTECTED]
Zend Framework           | http://framework.zend.com/

Reply via email to