Tom Tom - 4 years ago 178
PHP Question

Can I force SoapClient to return arrays as arrays?

I am fetching some data using SoapClient. I get this resuls from one of the calls:

stdClass Object
[payTransIncome] => stdClass Object
[item] => stdClass Object
[payTransId] => 141281
[payTransItId] => 630260
[payTransBuyerId] => 1311


However the docs of this WebAPI say
is an array.
Seems to me SoapClient found a one element array and converted it to a single stdClass object. And this makes it harder to parse because sometimes I think it might actually return more then 1 element.

Sure I can put everywhere checks
if (is_array())
but maybe there is a simple, more elegant way?

Answer Source

Please try to set features to SOAP_SINGLE_ELEMENT_ARRAYS in your SoapClient options:

$client = new SoapClient("some.wsdl", ['features' => SOAP_SINGLE_ELEMENT_ARRAYS]);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download