Rajeev Nath Verma
Rajeev Nath Verma

Reputation: 37

CodeIgniter &get_instance() not working in php5.6 version?

My codeigniter site is running properly in php5.4 version but when i upgrade my php version to php5.6.30 it is not working.

function &get_instance()
{       
    return CI_Controller::get_instance();
}

Above function is on 233 line of my file and it is returning null values.

Error - Fatal error: Class 'CI_Controller' not found in Coginiter_site\system\core\CodeIgniter.php on line 233

I have trace the error point - The code under system/core/common.php

if ( ! function_exists('load_class'))
{
    function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
    {
        static $_classes = array();

        // Does the class exist?  If so, we're done...
        if (isset($_classes[$class]))
        {
            return $_classes[$class];
        }

        $name = FALSE;

        // Look for the class first in the local application/libraries folder
        // then in the native system/libraries folder
        foreach (array(APPPATH, BASEPATH) as $path)
        {
            if (file_exists($path.$directory.'/'.$class.'.php'))
            {
                $name = $prefix.$class;

                if (class_exists($name) === FALSE)
                {
                    require($path.$directory.'/'.$class.'.php');
                }

                break;
            }
        }

        // Is the request a class extension?  If so we load it too
        if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php'))
        {
            $name = config_item('subclass_prefix').$class;

            if (class_exists($name) === FALSE)
            {
                require(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php');
            }
        }

        // Did we find the class?
        if ($name === FALSE)
        {
            // Note: We use exit() rather then show_error() in order to avoid a
            // self-referencing loop with the Excptions class
            exit('Unable to locate the specified class: '.$class.'.php');
        }

        // Keep track of what we just loaded
        is_loaded($class);

        $_classes[$class] = new $name();
        return $_classes[$class];
    }
}

return empty result This line createing a problem $_classes[$class] = new $name(); Please check it.

Upvotes: 3

Views: 999

Answers (2)

JP. Aulet
JP. Aulet

Reputation: 4398

You can try with this, change on CodeIgniter.php line 75

set_error_handler('_exception_handler');

to

set_exception_handler('_exception_handler');

Update:

If this is not working, maybe you can check this others things:

  1. Check if is a DB error (it's weird, but sometimes the DB error is shown as 'CI_Controller not found', for instance, with a bad db name).
  2. Check if changing: $config['log_threshold'] = 0; works for you
  3. Reinstall the whole CI framework system folder.

Here and here have the same problem, you can check all the answers.

If none of these works, try to post some code and context to your controller.

Hope it helps!

Upvotes: 1

Anubhav
Anubhav

Reputation: 362

Can you please follow the first solution of this? Hope it will clear your problem.

Upvotes: 2

Related Questions