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

Viewed 49395

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

4 Answers

None of the other answers in here actually solved this problem for me.

In this particular case I was using CodeIgniter and adding any of the following lines before the line that caused the error:

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

OR

 get_instance()->load->model('Authnet_Class')

OR

 include APPPATH . '/model/Authnet_Class.php';

Did not solve the problem.

I managed to solve it by invoking the class definition in the construct of the class where I was accessing Authnet_Class. I.e.:

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 ...

I now understand that the context where you access the Authnet_Class class, needs to have its definition present on the context's class construct (and not just before you invoke the properties of Authnet_Class).

I do not recommend this technique, but there is a way to get around this error :

if( get_class($myObject)=='__PHP_Incomplete_Class' )
    $myObject = unserialize(preg_replace('/^O:\d+:"[^"]++"/', 'O:'.strlen('MyClass').':"MyClass"', serialize($myObject)));

Having a good site architecture is obviously the right solution, but it can help temporarily until the problem is fixed

Related