Php 脚本试图执行方法或访问不完整对象的属性

Php 脚本试图执行方法或访问不完整对象的属性,php,wordpress,session,session-variables,Php,Wordpress,Session,Session Variables,我得到一个错误,完整的错误是: Fatal error: authnet_cart_process() [<a href='function.authnet-cart-process'>function.authnet-cart-process</a>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the cla

我得到一个错误,完整的错误是:

Fatal error: authnet_cart_process() [<a href='function.authnet-cart-process'>function.authnet-cart-process</a>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition &quot;AuthnetCart&quot; 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 in /home/golfetc/public_html/wp-content/plugins/sccp-2.4.0/authnet_functions.php on line 1266

您可以在第1266行看到,代码不允许我访问它的方法。我们将非常感谢您的帮助。谢谢

您的答案似乎在错误消息中

在取消序列化AUTHNET_CART之前,请包含定义它的类。手动或使用自动加载器

include PATH_TO_CLASS . 'AuthnetClassFilename.php';

if(isset($_SESSION['AUTHNET_CART'])) {//...
看起来您实际上也没有对其进行反序列化(我假设这是在将其装入会话之前序列化的?)


session\u start()之前,您需要
包括
/
要求
与类一起使用php

include PATH_TO_CLASS . 'AuthnetClassFilename.php';
session_start();

if (isset($_SESSION['AUTHNET_CART'])) {
    //...
}

这里的其他答案都没有为我解决这个问题

在本例中,我使用CodeIgniter并在导致错误的行之前添加以下任何行:

 $this->load->model('Authnet_Class');

没有解决问题

我通过调用我访问的类的
Authnet\u类的构造中的类定义来解决这个问题。即:

class MY_Current_Context_Class extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('Authnet_Class');
    }
    // somewhere below in another function I access Authnet_Class ...

我现在了解到,访问
Authnet\u类的上下文需要在上下文的类构造中显示其定义(而不仅仅是在调用
Authnet\u类的属性之前)。

您最初是如何设置
$\u会话['Authnet\u CART']
?在取消序列化之前包含AuthnetCart类,或者按照错误消息指示提供自动加载。$\u会话['AUTHNET\u CART']的var\u dump()是什么。如果它不是对象,也可能会导致问题?@RocketHazmat,我正在使用单实例方法初始化对象:公共静态函数getInstance(){//如果购物车不在会话中,请创建一个并将其放在那里//否则,如果(!isset($\u session['AUTHNET\u cart']),则从会话中获取它{self:$authnetcartance=new AuthnetCart();$_SESSION['AUTHNET_CART']=self:$authnetcartance;}其他{self:::$authnetcartance=$(AUTHNET_CART'];}返回self:$authnetcartance;}这是一个很老的问题,但我意识到发生此错误是因为序列化的数据不接受类所拥有的方法,而只接受其中的数据。因此,创建新实例并取消序列化会将方法添加到对象中,诸如此类。:PHow如果我们还不知道存储在会话中的类,我们会这样做吗?I如果用户登录,我将使用会话来存储用户对象,但是用户不必登录,因此在用户登录之前,我不会加载用户类,而这是在会话启动之后发生的。您是否有关于为什么这是PHP中的最佳实践的参考?
 $this->load->model('Authnet_Class');
 get_instance()->load->model('Authnet_Class')
 include APPPATH . '/model/Authnet_Class.php';
class MY_Current_Context_Class extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('Authnet_Class');
    }
    // somewhere below in another function I access Authnet_Class ...