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?
Please try to set features
to SOAP_SINGLE_ELEMENT_ARRAYS
in your SoapClient options:
$client = new SoapClient("some.wsdl", ['features' => SOAP_SINGLE_ELEMENT_ARRAYS]);
In older versions of PHP, SoapClient may ignore the "features" option. That was my case using PHP 5.3. But you can always cast an object of stdClass to array:
$client = new SoapClient("some.wsdl");
$objResult = $client->__soapCall("someFunction");
$objArray = (array)$objResult;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With