The script tried to execute a method or access a property of an incomplete object

Irfan picture Irfan · Dec 18, 2013 · Viewed 39.1k times · Source

I'm getting an error, the full error is:

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

I'm using session to store cart object in it and get it later at some point. The authnetCart is basically class for cart object.

// 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;
            }
        }
......

You can see at line 1266, the code doesn't allow me to access its method. Any help will be highly appreciated. Thanks

Answer

Vladimir picture Vladimir · Apr 28, 2014

You need to include / require the php with your class BEFORE session_start() like

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

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