Tags Archives

You are currently viewing all posts tagged with serialize.

Hello guys,

Do you use PHP? Do you use SOAP (you better :p) default extension?
This post is to be applied in that case and in that case only.
I don’t like NuSOAP and I think it has no use anymore.

This is a pretty neat ‘hack’. After sending some data to a webservice, say you need to save the XML that is easy.. PHP gives you your request in XML.

But say you need to save the payload as it is, just to re-send it later for some reason.
The payload is the final PHP Soap Object you constructed. (Works in arrays too as the PHP SOAP Object needs to be converted to array to be sent anyway).

You may say, well I will use serialize, and store the serialization of the object, however PHP serialize does NOT work with PHP SOAP Objects.
It doesn’t recognize the classes and the objects get malformed.

This is a trouble you only experience if you are really trying to rebuild a SOAP Object and not a simple array, but trust me there are cases in which you need SOAP Objects and not just arrays to enforce complicated hierarchy of namespaces.

You move on to json_encode/decode? Then it just won’t work as all the objects will be re-constructed into Array’s..

So what you actually need is a re-constructive  function that applies the correct decode transformation to a previous json_encode of the entire Payload SOAP Object.

So after you apply json_decode and you have a extensive Array. You apply this “””beautiful””” (read neat hack) function I created to reconstruct it accordingly.

You may want to add some switch’s in case you used any different type besides XSD_STRING or just SOAP_ENC_OBJECT when constructing the parameters.
I don’t use any other type seeing as it doesn’t matter when it gets transformed to XML.

Here’s the neat function:

Enjoy. Share!