How ext/soap converts SOAP data structures to PHP
I haven’t seen any documentation on how ext/soap converts SOAP results to PHP data structures, so I thought I would make a quick blog entry. If I get time, I will try to make this all pretty, confirm I am actually correct, and add it to the official docs.
Normally, the conversion is simple:
Becomes an attribute of “Person” and a value of “Adam” under a stdClass instance.
stdClass Object
(
[Person] => Adam
)
Attributes are also converted to properties:
stdClass Object
(
[gender] => male
)
When there is both text and attributes, the text is mapped to a property name of _ (underscore).
stdClass Object
(
[Person] => stdClass Object
(
[_] => Adam
[gender] => male
)
)
Of all the bits that might trip you up, this underscore mapping bit is it, as I don’t know where this came from. :)
However, it’s only done when there is straight-up text. If there is a nested XML element, then this doesn’t happen, as in:
This becomes:
stdClass Object
(
[Person] => stdClass Object
(
[Name] => Adam
[gender] => male
)
)
That’s all for now. The OSCON WiFi connection is super slow.
Comment by David on 1 August 2005:
I think wordpress ate your code examples. I don’t like it when wordpress does that. Bad wordpress!
Comment by Adam Trachtenberg on 5 August 2005:
Yea. Not only did it eat whitespace, it ate XML elements and attributes. Sorry.
Trackback by quoteunquote : web applications on 14 August 2005:
PHP5
PHP5 is going to be the focus of much of my time in the coming year or so – here’s a couple of pointers as to resources on this new version of the scripting language.
Comment by Phil on 18 January 2007:
Hi Adam,
I am new to soap. I search everywhere and still can’t find an answer or maybe I am going in the wrong direction and this is not possible. What does it mean when the client expect a returned of an XML Document in this format:
How can we returned .xml doc? Ever heard of this? I know we can returned string, float, array, etc. Do you have any idea? I am using php soap.
Phil
Comment by Alex on 19 January 2007:
Not sure what you mean there.
Do you just mean how to send an xml request using soap?