aryan kumar aryan kumar - 1 year ago 94
PHP Question

Single array element becomes object with Zend_Soap_Client

I'm using Zend_Soap_Client and encountering this issue:


If there's more than one child element then Zend return array and I can access like


but if there's only one child node it returns object like:


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


Answer Source

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 (see

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download