21. Appendix C - Troubleshooting
Content of this chapter
Appendix C gives support with troubleshooting.
21.1. C.1 PHP: SOAP-Client removes array of single-element list
With default settings of the PHP-SOAP client, single-element lists in SOAP responses are reduced to the element (array is not preserved).
The following response of ListContentBlocks contains exactly one content block:
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns2:ListContentBlocksResponse
xmlns:ns2="http://agnitas.org/ws/schemas"
xmlns:ns3="http://agnitas.com/ws/schemas">
<ns2:ContentBlock>
<ns2:contentID>123456</ns2:contentID>
<ns2:name>Text</ns2:name>
<ns2:targetID>0</ns2:targetID>
<ns2:order>1</ns2:order>
</ns2:ContentBlock>
</ns2:ListContentBlocksResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The WSDL documents define the content of ListContentBlockResponse as a list of an arbitrary number of <ContentBlock> elements, but in the PHP object, the embedding array is replaced by the single element itself. Here is the output of var_dump() on the response object:
object(stdClass)#2 (1) {
["ContentBlock"]=>
object(stdClass)#4 (4) {
["contentID"]=>
int(123456)
["name"]=>
string(4) "Text"
["targetID"]=>
int(0)
["order"]=>
int(1)
}
}
This requires an additional check, if the response contains an object or array. To avoid this, the PHP SOAP client can be instantiated with an additional configuration value, which forces PHP to preserve single element arrays. The instantiation looks like:
$config = array('features' => SOAP_SINGLE_ELEMENT_ARRAYS);
$client = new WsseSoapClient($wsdlUrl, $username, $password, null, $config);
Parameter 5 of the constructor can list any configuration value which is supported by the standard PHP SOAP client.
Now, with this configuration value, the object dump of the previous SOAP response shows the array (see line 3):