PHP problem with "__php_incomplete_class" PHP problem with "__php_incomplete_class" codeigniter codeigniter

PHP problem with "__php_incomplete_class"


The class definition had not been loaded, when PHP tried to deserialize the object in the session.

You can solve your problem by employing Autoloading.


The solution works, but you need to ensure that the class object definitions are read before session:

$autoload['libraries'] = array('**our class**','session','form_validation');


Look if you had any __autoload($class) and change it to use the spl_autoload_register() way. Example:

function __autoload($class){    if (file_exists(APPPATH . 'core/' . $class  .EXT)) {        require_once APPPATH . 'core/' . $class . EXT;    } else {        if (file_exists(APPPATH . 'libraries/' . $class . EXT)) {            require_once APPPATH . 'libraries/' . $class . EXT;        }    }}

would be changed to:

function CIautoload($class){    if (file_exists(APPPATH . 'core/' . $class  .EXT)) {        require_once APPPATH . 'core/' . $class . EXT;    } else {        if (file_exists(APPPATH . 'libraries/' . $class . EXT)) {            require_once APPPATH . 'libraries/' . $class . EXT;        }    }}spl_autoload_register('CIautoload');

This way, you'll be able of using all the PHP 5.3 power (and you won't have problem with composer autoloads and CI, ;D)

Explanation

If after a while using PHP 5.2 you start to use PHP > 5.3 and all the OO way of coding, you will start to use spl_autoload_register. With CI, in projects with PHP 5.2, as you couldn't use spl_autoload_register people used a known hack to autolad classes using a function __autoload($class) that they usually wrote on the config.php file. Problem is when you mix both, the spl_autoload_register function will override your __autoload class and the error the question ask for will arise.