“__php_incomplete_class"的 PHP 问题 [英] PHP problem with "__php_incomplete_class"

查看:33
本文介绍了“__php_incomplete_class"的 PHP 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 CodeIgniter 开发一个网站并创建了一个用户和一个会话:

I'm developing a website with CodeIgniter and have created a User and a session:

$user->first_name = 'Gerep';
$user->gender = 'M';
$user->age = '26';


$this->session->set_userdata('user', $user);

但是当我尝试访问会话对象时:

But when I try to access the session object:

echo $this->session->userdata('user')->first_name;

它返回一个错误:类 __PHP_Incomplete_Class 的对象无法转换为字符串

我一直都是这样工作的,从来没有遇到过这个问题.

I have always worked like that and never had that problem.

谢谢!

推荐答案

当 PHP 尝试反序列化会话中的对象时,类定义尚未加载.

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.

这篇关于“__php_incomplete_class"的 PHP 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆