在会话中保存对象的问题

In my project, I have this line, in the core file:

$LoggedIn = isset($_SESSION['User']) ? unserialize($_SESSION['User']) : false;

Core: http://pastebin.com/9HMP11bG

and under the login method, it has the corrosponding:

$_SESSION['User'] = serialize($User);

User Repo: http://pastebin.com/vNehc2Hm

User: http://pastebin.com/4UXT79MU

When I try to access the $LoggedIn object, it gives me an error like this:

Fatal error: Uncaught Error: Cannot use object of type __PHP_Incomplete_Class as array in C:\xampp\htdocs\jalawebs\dev\webcofounder\web\controller\index\index.php:14 Stack trace: #0 C:\xampp\htdocs\jalawebs\dev\webcofounder\config\core.php(111): require() #1 C:\xampp\htdocs\jalawebs\dev\webcofounder\index.php(9): require('C:\\xampp\\htdocs...') #2 {main} thrown in C:\xampp\htdocs\jalawebs\dev\webcofounder\web\controller\index\index.php on line 14

This happens when you call to a property of an unserialized object that is not defined in the script itself.

Creating a class like so new User() will invoke the autloader to load the script where unserialize() does not.

You could do the following:

$o = unserialize($yourstring);
if(is_object($o) && class_exists(get_class($o))){ // invoke the autoloader
  echo $o->LoggedIn;
}

Or just include the script directly with include_once() or require_once().