-- Rob Allen <[email protected]> wrote
(on Wednesday, 29 April 2009, 08:40 AM +0100):
> On 27 Apr 2009, at 19:37, Bart McLeod wrote:
>     Matthew Weier O'Phinney schreef:
>         -- Bart McLeod <[email protected]> wrote
>         (on Monday, 27 April 2009, 06:11 PM +0200):
>             For all of you who are also wondering what is needed to replace 
> the good old
> 
>             require_once 'Zend/Loader.php';
>             Zend_Loader::registerAutoLoad();
> 
>             This is what is needed in it's most basic form:
> 
>             require_once 'Zend/Loader/Autoloader.php';
>             $loader = 
> Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true);
> 
> 
>         In most cases, you won't even need to call setFallbackAutoloader(), 
> btw.
> 
> 
>     I tried immediately, but in my case I need it. What does it do actually?
>     Will look that up in the manual.
> 
> I needed setFallbackAutoloader() too so that my other libraries in the 
> library/
> folder that follows the PEAR class naming convention continued to autoload.

PEAR doesn't have a common prefix, which leads to some problems. (To be
fair, though, PEAR2 will introduce a common prefix and namespace, btw.)

If you have a lot of libraries with different prefixes in library/, yes,
setting the autoloader to act as a fallback autoloader is a good idea.
However, if the list is finite, it's a good idea to set the namespaces
explicitly, as they will match faster and more accurately... which you
show below:

> Another alternative is to use something like this:
> 
> require_once 'Zend/Loader/Autoloader.php';
> $loader = Zend_Loader_Autoloader::getInstance();
> $loader->registerNamespace('App_');
> $loader->registerNamespace('BRI_');
> 
> I can't emphasise enough how important it is to also do:
> $loader->suppressNotFoundWarnings(false);
> 
> whilst in development!  Otherwise you get a blank screen when the autoloader
> fails to load a file because there's a syntax error (or the signature of an
> interface function has changed)!

That's good advice... and I'm surprised that I didn't make the flag
default to this. I'll file an issue in the tracker to rectify this
situation, as we wanted it defaulting to no suppression. (When you're
not using it as a fallback autoloader, there's little to no need for
suppression.)

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/

Reply via email to