PHP - 脚本尝试执行方法或访问不完整对象的属性
我正在使用 CI,我有一个 UserModel,它根据登录信息选择用户并设置 userVO 并在会话中添加此 userVO,如下所示:
$this->session->set_userdata('user', $userVO);
当我尝试访问此会话时,它返回此错误:
Message: main() [function.main]: The script tried to execute a method
or access a property of an incomplete object. Please ensure that the
class definition "UserVO" of the object you are trying to operate on
was loaded _before_ unserialize() gets called or provide a __autoload()
function to load the class definition.
我发现了一个“解决方案”,我需要 CI 在会话类之前加载 UserVO 类并且它可以工作。
问题是我有很多 os VO 类,我需要在会话中使用它们,并且自动加载它们是一件坏事,因为我不会同时需要它们。
有什么解决方法吗?
预先感谢您的任何帮助。
I'm using CI and I have a UserModel that selects the user based on login information and sets a userVO and add this userVO in a session like this:
$this->session->set_userdata('user', $userVO);
When I try to access this session it return me this error:
Message: main() [function.main]: The script tried to execute a method
or access a property of an incomplete object. Please ensure that the
class definition "UserVO" of the object you are trying to operate on
was loaded _before_ unserialize() gets called or provide a __autoload()
function to load the class definition.
I have found a "solution", I need CI to load the UserVO class before session class and it works.
The problem is that I have lots os VO classes and I'll need them inside the session and is a bad thing to autoload them because I won't need them all at the same time.
Is there any workaround?
Thanks in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发生的事情是您将类的实例保存到会话中。为了恢复它,您首先需要加载它作为实例的基类。您可能有很多 VO 类的“实例”,而不是很多 VO 类。您只需要加载具有类声明的文件。
类实例实际上只包含与基类相比发生更改的内容,而不是整个类。因此它需要底层类知道“默认值”是什么。
Whats going on is that you are saving an instance of the class to the session. In order to restore it, you first need to load the base class it is an instance of. You likely have lots of "instances" of the VO class, rather than lots of VO classes. You just need to load the file that has the class declaration.
The class instance really only contains what has changed from the base class, not the whole class. So it needs the underlying class to know what the "defaults" are.