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

Issue Type: Patch Created: 2009-09-09T17:47:35.000+0000 Last Updated: 2011-07-05T15:19:50.000+0000 Status: Resolved Fix version(s): - 1.11.2 (30/Dec/10)

Reporter: Nicola Avancini (niscio) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Application

Related issues: - ZF-6484



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!


Posted by Matthew Weier O'Phinney (matthew) on 2010-06-18T09:11:05.000+0000

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.

Posted by Matthew Weier O'Phinney (matthew) on 2010-06-18T09:27:56.000+0000

This appears to duplicate ZF-6484.

Posted by Nicola Avancini (niscio) on 2010-06-21T02:49:55.000+0000

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

<pre class="highlight">
(--)//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

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

Posted by Matthew Weier O'Phinney (matthew) on 2011-07-05T15:19:50.000+0000

Fixed with ZF-11219 for release 1.11.2.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.