I have to deal with a SOAP API that doesn’t follow the the standard way of acting like a SOAP API. While 99 percent of the time, I can interact with it using the normal PHP SoapClient, but sometimes, I can’t do that and I have to revert to calling the SOAP method using curl.

It works, it just means I have to do more work than I care to do. One of the issues I dealt with today was that I didn’t want rewrite the method that was processing the SOAP response. The SoapClient returns a stdClass in whatever structure the SOAP API defined in its wsdl. With curl, I get raw XML and I needed to convert it to a stdClass. I did it like this.

The $response object is a SimpleXMLElement object. That’s super useful most of the time, but for, I didn’t want to rewrite the method that processes this response to use SimpleXMLElements. So that’s why I didn’t the json_encode then json_decode. The json_encode doesn’t carry with it specific class information, it’s just an “object.” So then json_decode decodes that into a stdClass, which is what my method was expected.

The $this->curl($xml) is just a method I created when I need to make a curl call instead of SoapClient call. It looks like this.