I’m integrating the Whistl shipping carrier in our custom framework through SOAP protocol.

The fastest way is to build an array with all the required elements and send it to Whistl API.

Working with SOAP in php is very simple. Especially when you use the array as a container to pass to SOAP.

Example of SOAP initialisation and the method to be called with the array:

But later, going a bit closer through documentation spotted this bit of requirement for the request:

And at that moment I realised, there’s no way I could pass multiple elements with the same tag (<parcelProduct> ) using the array.

Overcome the multiple elements restriction

Tried multiple approaches and the best solution (the one and only one)  was to use the empty generic php Object.
It allows you to pass a request with same multiple elements, for example the upper XML request would look like:

After the object is properly build and is passed to the method as in the following example:

That’s what I’m calling a neat solution 😀 !

P.S. Don’t forget to pass every bit of code through GIT, that’s a life saver.