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

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


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'])) {    //...}


It seems like your answer is in the error message.

Before unserializing AUTHNET_CART, include the class which defines it. Either manually, or using an autoloader.

include PATH_TO_CLASS . 'AuthnetClassFilename.php';if(isset($_SESSION['AUTHNET_CART'])) {//...

It doesn't appear that you're actually unserializing it either (I'm assuming this was serialized before stuffing it into the session?)

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


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