ZF-11330: Zend_Loader_PluginLoader does not properly handle 5.3 namespaces

Issue Type: Bug Created: 2011-04-28T20:55:10.000+0000 Last Updated: 2012-06-04T14:05:13.000+0000 Status: Resolved Fix version(s): - 1.12.0 (27/Aug/12)

Reporter: Rob Zienert (pievendor) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Loader

  • FixForZF1.12
  • zf-crteam-priority
  • zf-crteam-review

Related issues: - ZF-7350

Attachments: - zf-11330-fix.diff


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

<pre class="highlight">
$classFile = str_replace('_', DIRECTORY_SEPARATOR, $name) . '.php';

The following patch corrects the issue:

<pre class="highlight">
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;


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:

<pre class="highlight">
$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.

Posted by Adam Lundrigan (adamlundrigan) on 2012-06-04T14:05:13.000+0000

Fixed in trunk (1.12.0): r24877

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.