PHP - 脚本尝试执行方法或访问不完整对象的属性

发布于 2024-12-25 03:40:23 字数 684 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

⒈起吃苦の倖褔 2025-01-01 03:40:23

发生的事情是您将类的实例保存到会话中。为了恢复它,您首先需要加载它作为实例的基类。您可能有很多 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文