2009年6月6日星期六

Re: [fw-mvc] Regression with Autoloading?

Actually, I'm wrong on this. The exception is caught immediately in Zend_Loader_Autoloader::_autoload then returns false so it should continue trying to load using the rest of the stack. I don't know why your autoloader doesn't get called.

   -- Mon


On Sun, Jun 7, 2009 at 12:20 PM, Mon Zafra <monzee@gmail.com> wrote:
>From my understanding, the SPL autoloader stack works in a FIFO basis, so Zend_Loader_Autoloader's internal autoloader (which is just Zend_Loader::loadClass) is invoked first since you registered your namespace. The old autoloader won't do any transformation to the 5.3-namespaced class name (if there are no underscores), it just adds the extension. It might work with 5.3-namespaced classes and Windows since the namespace and directory separators are the same. However, if it fails to include the class, it throws an (uncatchable) exception which triggers a fatal rather than going through the rest of the stack.

So my suggestion is to
1. register your autoloader first, but modify it to return early if the class is not 5.3-namespaced
2. change Zend_Loader_Autoloader's default autoloader to yours (via setDefaultAutoloader()), but modify it to replace underscores with slashes too
3. use Zend_Loader_Autoloader::pushAutoloader($callback, $namespace) rather than registerNamespace()

   -- Mon



On Sun, Jun 7, 2009 at 11:21 AM, Abraham Block <atblock@gmail.com> wrote:
I had been including my own autoloader for PHP 5.3 style classes (my understanding is that somebody is going to be adding this to PHP 5.3 itself at some point), and now after I updated my svn:externals for ZF (rev 15923), my app stopped working. It seems that when I call Zend_Loader_Autoloader::registerNamespace, this autoloader wants to take over all the other autoloaders or something like that...

Allow me to demonstrate.

This code works:

require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();

function autoload($class) {
    $class = str_replace('\\', '/', $class);
    include $class . '.php';
}

spl_autoload_register('autoload');
$a = new Zend_Acl;
$b = new My\Class;


but if I add $autoloader->registerNamespace('AB');

all of a sudden my autoload function is ignored!





没有评论: