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
Posted by Antonio J GarcĂa Lagar (ajgarlag) on 2012-04-25T11:51:25.000+0000
Submitted a diff file with the unit tests and the patch to solve the bug.
Posted by Adam Lundrigan (adamlundrigan) on 2012-05-07T00:32:33.000+0000
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:
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.
Posted by Adam Lundrigan (adamlundrigan) on 2012-06-04T14:05:13.000+0000
Fixed in trunk (1.12.0): r24877