CodeIgniter Forums
CI 3.1.3 subclassing CI_Lang does not work - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: CI 3.1.3 subclassing CI_Lang does not work (/showthread.php?tid=67553)



CI 3.1.3 subclassing CI_Lang does not work - druid99 - 03-08-2017

Hey,

I did some testing with upgrading from 2.x to 3.x and I ran into an issue with subclassing of (core) CI_Lang with MY_Lang.

I can see that constructor of MY_Lang and CI_Lang are called, which is nice.

However if 

Code:
$ci->load->library('Lang',$pParams);

is executed I get an error

Code:
        // If we got this far we were unable to find the requested class.
        log_message('error', 'Unable to load the requested class: '.$class);
        show_error('Unable to load the requested class: '.$class);

The reason is that

Code:
        // Is this a stock library? There are a few special conditions if so ...
        if (file_exists(BASEPATH.'libraries/'.$subdir.$class.'.php'))
        {
            return $this->_ci_load_stock_library($class, $subdir, $params, $object_name);
        }


Is not executed because Lang is in directory '/core' and

Code:
            // Safety: Was the class already loaded by a previous call?
            if (class_exists($class, FALSE))

failes because class_exists('Lang') is not TRUE. It is TRUE for 'CI_Lang' and 'MY_Lang' though.


Am I missing something here? Any toughts?

Thanks!


RE: CI 3.1.3 subclassing CI_Lang does not work - Narf - 03-08-2017

Libraries in core/ are always loaded, unconditionally.

Just don't call load->library() for them.


RE: CI 3.1.3 subclassing CI_Lang does not work - druid99 - 03-08-2017

Awesome! Thanks Smile