-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible error in JLoader::registerPrefix #7224
Comments
try |
That won't work. The $prepend parameter (which you set to true) only has affect if you called JLoader::registerPrefix with the same prefix more than one time. In the sample I mentioned above, I register two different prefixes. And the first registered prefix is a part of the second prefix |
@joomdonation but you tried or you about theory? 😉 |
@Fedik Yes, I tried and received the error: Class 'OSMembershipController' not found |
If the longer prefix (OSMembership) is registered before the shorter prefix (OS) then it works. We can control it if the code is from same extension but if it is from two different extensions, it will be difficult. So unless I am wrong, I think this is a bug. |
Issue description
Recently, I had issue with auto-load in my custom extension using JLoader::registerPrefix:
I have a MVC library which has prefix OS. OSController, OSModel.... So I register that prefix using this code:
My component has the name com_osmembership and I want my controllers, models, views.... to be auto-loading as well, so I register another prefix:
The problem happens when Joomla tries to load a class in my component, for example OSMembershipController. Joomla sees that this class started with OS, so It tries to find that class from PATH_TO_LIBRARY_FOLDER as starting point for finding. Of course, it could not found the class and result class not found error. As you can see, I expect that Joomla will find that class from PATH_TO_MY_COMPONENT. If Joomla does that, it will find the class and won't return class not found error.
So the question is: Is this a bug ? or I am using it in a wrong way?
Possible solution:
If we agree that this is a bug, I think we can modify the code of _autoload. The idea is looping over all the registered prefix until we found a class. The change code is:
That code solve the issue but will make the system loop few more times, not sure it will cause any performance issue?
The text was updated successfully, but these errors were encountered: