Tom Tom - 4 months ago 31
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
payTransIncome
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

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

$client = new SoapClient("some.wsdl", ['features' => SOAP_SINGLE_ELEMENT_ARRAYS]);