About the Author

author photo

Adam Trachtenberg is the Director of the LinkedIn Developer Network, where he oversees developer relations and marketing for the LinkedIn Platform. Before LinkedIn, Adam worked at eBay in platform product management and marketing. Even earlier, he co-founded Student.Com and TVGrid.com. Adam is the author of PHP Cookbook and Upgrading to PHP 5. He lives in San Francisco.

See All Posts by This Author

PHP 5 SOAP Hacking

My new favorite PHP 5 SOAP feature is the classmap option. By default, ext/soap converts complexTypes into stdClass objects. However, that’s only useful for reading the data.

Using the classmap option, you can specify how ext/soap should map complexTypes to PHP classes. This allows me to write methods to implement iterators and pretty-printing of objects.

I hope I can construct a series of model classes (similar to what Services_Ebay), so if you have an User object from populated from the output of, say, GetUser, you’ll be able to call a GetFeedback method on that object, and have it make a GetFeedback API call and fill in the necessary data based on what’s already stored within the object as properties.

Ideally, I’ll be able to do some magic __call() overloading, so I don’t even need to explicitly define these methods, but I can just write one magic base class. I’m not sure if that will work, but it’s my weekend hacking project.

Also, while I’m at it, I’m having problems getting the compression option to work. I get a nasty SoapClient::__doRequest(): SSL: fatal protocol error when I try. It looks as if zlib is enabled, so I don’t know if SSL and Gzip don’t play nicely together, or if my SOAP server is busted, or what. I’ll work on debugging this, but if anyone else has something to share, I’d be happy to hear it.

There Are 3 Responses So Far. »

  1. If you have a simple reproducing script that accesses a public service I can take a look at it. Post it or email it to me.

  2. Hi Adam,

    Have you had any luck using classmap to pass an array via PHP5 SOAP server? We’re having trouble passing back a list of information. For example we’d like to return a list of users in the userInfo data type:

    We tested our listUsers function outside the SOAP server and it properly creates an array. However, our SOAP client reports that listUsers returns an empty array.

    By the way, the listUsers function returns a class which constructs an array. We mapped that array class to the WSDL list via classmap.

    It seems like the array is not getting populated on the server side because we’re missing a step in constructing an array class properly, or the array is not getting mapped to the list described in the WSDL. Classmap has worked for us for other complex data types, so the issue is specifically passing back an array represented in WSDL per the above.

    Any ideas?

    Thank you very much.

    Have a great weekend!

    Best Regards,

  3. Darry —

    I have never used the SOAPServer part of ext/soap, so unforunately I cannot help you. I suggest you make a small test case and report it as a bug.