user-library class loading |
[eluser]sipsniffa[/eluser]
Hi, I recently ran into a problem when trying to load my own CodeIgniter library. I initially posted a query to the 'Code and Application' forum and finally posted on what may be a bug. The problem was related to the use of the 'subclass_prefix' configuration option and its possible misuse in the CI code base or missing documentation. The problem is caused by trying to load a user-library (placed in application/libraries/) without assigning a value to the 'subclass_prefix' configuration option (i.e. 'subclass_prefix' took the default, empty string value). This results in user library classes being deemed attempts to subclass CodeIgniter library classes (code snipped from _ci_load_class() in system/library/Loader.php): Code: $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.EXT; Code: $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.EXT; I think that the initial subclass test doesn't make sense when ‘subclass_prefix’ is the empty string. Might this be considered a bug, either in the documentation or in code?: 1. Documentation Bug I haven't seen it mentioned in the docs, but if a client wishes to implement a CI user-library then it would be helpful if the docs stated that a value must be assigned to the 'subclass_prefix' configuration option - even when no subclassing of CI libraries is to undertaken. 2. Code Bug One possibility that comes to mind as a code fix would be to prohibit library subclassing if the configuration setting 'subclass_prefix' contains it's default, empty string value (''). I think this could be achieved by placing a guard around the subclass test code - which I highlighted above - like so: Code: // Subclassing only allowed when 'subclass_prefix' is defined. While looking at _ci_load_class() there appears to be code that is ripe for refactoring. I'd be grateful if someone could explain the process used by EllisLab when handling community offerings of code. Thanks, Paul. |
Messages In This Thread |
user-library class loading - by El Forum - 12-16-2008, 07:03 AM
user-library class loading - by El Forum - 12-16-2008, 07:22 AM
user-library class loading - by El Forum - 12-16-2008, 07:55 AM
user-library class loading - by El Forum - 03-21-2009, 05:35 PM
|