4

我正在使用 Zend_Soap_Client 并遇到此问题:

<parent>
    <child><name>abc</name></child>
    <child><name>def</name></child>
</parent>

如果有多个子元素,则 Zend 返回数组,我可以像这样访问

$result->parent->child[0]->name

但如果只有一个子节点,它会返回如下对象:

$result->parent->child->name

您能否让我知道我的方法有什么问题或如何克服它?

我的示例代码:

$client = new Zend_Soap_Client('url', array('wsdl'=>'url));
$result = $client->getResult();

我正在使用zend 1.9。PHP的本机SoapClient也会出现同样的问题

谢谢!

4

1 回答 1

9

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));
于 2013-09-30T06:35:44.947 回答