Issues

ZF-7063: Zend_Loader_Autoloader::getClassAutoloaders() incorrectly detects module namespaces...

Description

My application is structured as follows...

application modules admin sales sales-admin

In Zend_Loader_Autoloader (line 308), it detects the namespace incorrectly and returns the wrong autoloader for all classes in sales-admin (instead bringing back those from Sales.

Proposed fix is to replace line 308 if (0 === strpos($class, $ns)) {

with the following if (0 === strpos($class, $ns.'_')) {

This seems to fix things, but I'm not entirely sure if that's going to cover it... maybe a little regex would be more helpful...

Comments

I would just like to add that I am having the same issue with 2 modules/namespaces of my own.

news & news-aggregator

Yes, I have the same problem too. If two modules begin with the same prefix, then Zend_Loader_Autoloader will return invalid result.

For example, if we have "foo" module and "foo-bar" module, Zend_Loader_Autoloader will return autoloaders for the first module ("foo").

This is bug example:


new Zend_Application_Module_Autoloader(array('namespace' => 'Foo', 'basePath' => dirname(__FILE__)));
new Zend_Application_Module_Autoloader(array('namespace' => 'FooBar', 'basePath' => dirname(__FILE__)));
$autoloaders = Zend_Loader_Autoloader::getInstance()->getClassAutoloaders('FooBar_Model');
Zend_Debug::dump($autoloaders[0]->getNamespace());
// Will output: string(3) "Foo"

This was fixed for 1.9.1 (see ZF-7473)