dongshi3818 2017-01-19 12:25
浏览 21
已采纳

在会话中保存对象的问题

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
  • 写回答

1条回答 默认 最新

  • duandu8707 2017-01-19 12:34
    关注

    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().

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习残差模块模型
  • ¥20 两个不同Subnet的点对点连接
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)