Issues

ZF-11330: Zend_Loader_PluginLoader does not properly handle 5.3 namespaces

Description

load() method (line 373) improperly handles class file conversions with namespaces by only checking for underscores in the $name variable:


$classFile = str_replace('_', DIRECTORY_SEPARATOR, $name) . '.php';

The following patch corrects the issue:


diff --git a/Zend/Loader/PluginLoader.php b/Zend/Loader/PluginLoader.php
index d4003dc..55a4d4a 100755
--- a/Zend/Loader/PluginLoader.php
+++ b/Zend/Loader/PluginLoader.php
@@ -372,7 +372,11 @@ class Zend_Loader_PluginLoader implements Zend_Loader_PluginLoader_Interface
 
         $registry  = array_reverse($registry, true);
         $found     = false;
-        $classFile = str_replace('_', DIRECTORY_SEPARATOR, $name) . '.php';
+        if (false !== strpos($name, '\\')) {
+            $classFile = str_replace('\\', DIRECTORY_SEPARATOR, $name) . '.php';
+        } else {
+            $classFile = str_replace('_', DIRECTORY_SEPARATOR, $name) . '.php';
+        }
         $incFile   = self::getIncludeFileCache();
         foreach ($registry as $prefix => $paths) {
             $className = $prefix . $name;

Comments

Submitted a diff file with the unit tests and the patch to solve the bug.

The issue here is that Zend_Loader_PluginLoader supports namespaces in the class prefix (see ZF-7350), however one cannot load a class from a sub-namespace of the prefix namespace. Test case which fails w/ current implementation:


$loader = new Zend_Loader_PluginLoader(array());
$loader->addPrefixPath('Zfns\\', dirname(__FILE__) . '/_files/Zfns');
$className = $loader->load('Foo\Bar');

I've tested the patch and verified that it works as advertised. I've attached new patches as the OP's patches were in git format.

Fixed in trunk (1.12.0): r24877