?
avatar berserkerx
berserkerx
12 Jul 2017

Steps to reproduce the issue

JLoader::registerNamespace('B', JPATH_SITE . '/libraries/app/vendor/B/src', $reset = true, $prepend = false, $type = 'psr4');
\B\B::anyMethod();

Expected result

Autoloading \B\B class and calling anyMethod.

Actual result

Class not found.

Additional comments

File: libraries/loader.php

  1. if (strpos($class, $ns) === 0) is not enough, there can be two namespaces AAA and AAAB, both starting with 'AAA'. Valid check is:
$nsLen = strlen($ns);

if (strpos($class, $ns) === 0 && isset($class[$nsLen]) && $class[$nsLen] === DIRECTORY_SEPARATOR)
  1. $classFilePath = $path . DIRECTORY_SEPARATOR . str_replace($nsPath, '', $classPath);
    It's totally wrong to replace namespace name in fully qualified class name. Consider \Apple\AppleBridge\AppleNice\AppleClass

Valid behavior is to strip only leading namespace part:

$classFilePath = $path . DIRECTORY_SEPARATOR . substr($classPath, $nsLen + 1);

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
5.00

avatar berserkerx berserkerx - open - 12 Jul 2017
avatar joomla-cms-bot joomla-cms-bot - labeled - 12 Jul 2017
avatar laoneo
laoneo - comment - 17 Jul 2017

Guess this one can be closed as we have a pr.

avatar zero-24 zero-24 - change - 17 Jul 2017
Status New Closed
Closed_Date 0000-00-00 00:00:00 2017-07-17 18:12:14
Closed_By zero-24
avatar zero-24 zero-24 - close - 17 Jul 2017

Add a Comment

Login with GitHub to post a comment