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

2022-08-30 15:13:26

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

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

我正在使用会话将购物车对象存储在其中,并在以后的某个时候获取它。authnetCart基本上是购物车对象的类。

// Check cart in session
    if(isset($_SESSION['AUTHNET_CART'])) {
        // Get cart from session
        $authnetCart = $_SESSION['AUTHNET_CART'];
        foreach($authnetCart->getCartItems() as $item) {  // Line#1266
            if ($item->getItemId() == $subscription_details->ID ) {
                $addNewItem = false;
                break;
            }
        }
......

您可以在第 1266 行看到,代码不允许我访问其方法。任何帮助将不胜感激。谢谢


答案 1

你需要/php与你的类之前喜欢includerequiresession_start()

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

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

答案 2

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

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

include PATH_TO_CLASS . 'AuthnetClassFilename.php';

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

看起来你实际上也没有取消序列化它(我假设这是在将其塞入会话之前序列化的?

if(isset($_SESSION['AUTHNET_CART'])) {
        // Get cart from session

        /** UNSERIALIZE **/
        $authnetCart = unserialize($_SESSION['AUTHNET_CART']);
        foreach($authnetCart->getCartItems() as $item) {  // Line#1266
            if ($item->getItemId() == $subscription_details->ID ) {
                $addNewItem = false;
                break;
            }
        }
...

推荐