Issues

ZF-7815: In Zend Application with namespace "Default_", there is some errors to load modules with namespace "Default_ModuleName_"

Description

if i set to the module the namespace Default_ModuleName the class Zend_Loader_Autoloader return the wrong Default_ resource instead of Default_ModuleName.

Becouse the class search the first Resource with the 0 === strpos($class, $ns)

But the resource is put by Zend_Application_Module_loader.... in this order 1. Default_ 2. Default_ModuleName etc..

I propose to replace in Zend_Loader_Autoloader at line 304 the foreach with the for that begins the search from the bottom up like this.. //foreach (array_keys($this->_namespaceAutoloaders) as $ns) { $keys = array_keys($this->_namespaceAutoloaders); for($i = count($keys); $i > 0 ; $i--){
$ns = $keys[$i - 1]; if ('' == $ns) { continue; } if (0 === strpos($class, $ns)) { $namespace = $ns; $autoloaders = $autoloaders + $this->getNamespaceAutoloaders($ns);
break; } }

and remove the control in Zend_Loader_Autoloader_Resource at line 147 that check if the first argument of split of classname by _ is equal to namespace loaded // if (!empty($namespaceTopLevel)) { // $namespace = array_shift($segments); // if ($namespace != $namespaceTopLevel) { // // wrong prefix? we're done // return false; // } // }

Excuse my poor English. I do not know if this model was intended or not but I felt much more comfortable that a module could be prefixed with the application, but I hope it is not interfering.

Good Work!

Comments

I'm actually not entirely clear from your description what the issue you're experiencing is.

Can you please provide the following: * Short reproduce code displaying the issue * What your expectations are * What the actual result is

In your case, it sounds like autoloading of module resources is not working as expected, but it also sounds like you may be using a compound class prefix. Please make sure your example fully illustrates any such configuration.

This appears to duplicate ZF-6484.

Yes, is duplicate...

In my case i create an application with namespace "Apps_", then when i tried to create modules extension i trie to assign module namespace like "Apps_Blog", but this don't work becouse Zend_Loader_autoloader takes the first namespace available (in this case Apps_).

I tried to post a simple patch for resolv this issue

Zend_Loader_Autoloader at line 304


(--)//foreach (array_keys($this->_namespaceAutoloaders) as $ns) {
(++)$keys = array_keys($this->_namespaceAutoloaders);
(++)for($i = count($keys); $i > 0 ; $i--){
       $ns = $keys[$i - 1];
       if ('' == $ns) { continue; }
       if (0 === strpos($class, $ns)) { $namespace = $ns; $autoloaders = $autoloaders + $this->getNamespaceAutoloaders($ns); break; }
    }

Zend_Loader_Autoloader_Resource at line 147


(--)// if (!empty($namespaceTopLevel)) {
(--)//    $namespace = array_shift($segments);
(--)//    if ($namespace != $namespaceTopLevel) { // 
(--)//        wrong prefix? we're done 
(--)//        return false; 
(--)//    }
(--)// }

Fixed with ZF-11219 for release 1.11.2.