I'm using Zend_Soap_Client and encountering this issue:
<parent>
<child><name>abc</name></child>
<child><name>def</name></child>
</parent>
If there's more than one child element then Zend return array and I can access like
$result->parent->child[0]->name
but if there's only one child node it returns object like:
$result->parent->child->name
Can you please let me know what's wrong with my approach or how can I overcome it?
My sample code:
$client = new Zend_Soap_Client('url', array('wsdl'=>'url));
$result = $client->getResult();
I'm using zend 1.9. The same issue happens with PHP's native SoapClient
Thanks!
Personally I do not see the need to use Zend_Soap_Client
instead of SoapClient
because the Zend version does not add anything beneficial, but on the other hand the solution applies to both:
There is an options array parameter in the original SoapClient
that accepts plenty of things, and especially this below (ref):
The features option is a bitmask of SOAP_SINGLE_ELEMENT_ARRAYS,...
With this option, all array structures in the soap response are not reduced to one single element if they contain only one, but left as is. You are always accessing an array then, which is easier than switching depending on the content.
Example:
$s = new SoapClient($wsdl, array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));
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