Skip to content
Advertisement

Associative array key becomes param in XML when passed to SoapClient

I have an associative array:

JavaScript

(Nulls hold actual values in reality)

When I check __getLastRequest I completly lose the keys in the generated XML.

SoapClient,

JavaScript

Please note that I have a NON WSDL connection to the endpoint.

The generated XML will have a field value of <param[keyNum] xsi:type="xsd:typeOfVariable"> instead of having the actual key value from the associative array, <trid> for example.

JavaScript

Advertisement

Answer

Contrary to what the PHP manual says, it seems arguments is never interpreted as an associative array.

If we try this simple test:

JavaScript

we get:

JavaScript

We see that the parameter names are ignored.

Now if we try what the other answer suggests (wrap the array in another array):

JavaScript

we get:

JavaScript

We see that there is a single parameter whose type is Map. That’s not what we want.

The solution is to use the SoapParam class:

JavaScript

Now we get what we wanted:

JavaScript

Note that you can easily convert an associative array to SOAP parameters like this:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement