Ticket #22 (closed Bug: fixed)
CI_Loader::_ci_load_class() trys to redeclare extended libraries
| Reported by: | Tido | Owned by: | |
|---|---|---|---|
| Priority: | minor | Milestone: | 1.0 |
| Component: | Version: | ||
| Keywords: | loader, load | Cc: |
Description
http://codeigniter.com/bug_tracker/bug/1779/
When calling load->library() on a core class that has not been extended the loader checks to see if the class has already been instantiated and returns without reloading it. However, if you extend a class, that check is not performed so if an extended library has been loaded somewhere and you try to load it again you get a PHP fatal error for redeclaring a class.
The pertinent code is in system/libraries/Loader.php in the _ci_load_class() method starting on line 676. A conditional should be placed above line 693 checking if the class has already been loaded and returning without further action if it has. The conditional should be almost identical to that found on lines 713-718.
The sample code in this report assumes a MY_Encrypt.php exists in application/libraries/. It is also an overly simplified but accurate representation of the problem--In a real world application it is more likely that two other libraries would be loaded loaded both of which attempt to load ‘encrypt’.
Woody and Jim have a patch that fixes this issue and adds some functionality at http://wgilk.com/code/MY_Loader.php
