Cannot Use Object of Type stdClass as Array – Fixing Soap API Error

apimagento-1.7soapwsdlxml

This is my first time trying to pull information with the Magento soap API. I have used SOAP previously on the Orange M2M connect server.

Ive hit a stump and im not sure where to go from here. I have managed to pull salesOrderList from Magento and var_dump them, and all the data is there. But when i try to access say the increment_id using the method below i get this error:

Cannot use object of type stdClass as array in C:\xampp\htdocs\magento_soap_client\fulfilment\soap\class.orders.php

Code used to try and get the increment id:

$this->m_orders = $this->client->salesOrderList($this->sessionID);

foreach($this->m_orders as $o){
            var_dump($o['increment_id']);
        }

Why am i getting this error?

I haven't parsed the data through an XML Parser yet, do i need to before accessing the information? The reason i ask is because this is what i had to do when working with the orange m2m connect soap server.

Thanks

Best Answer

This means that $o is not an array. It's an instance of stdClass. Try like this:

var_dump($o->increment_id);

or

var_dump((array)$o['increment_id']);