I'm having some trouble with PEAR soap and a response from a webservice
when the number of results is one or more than one.
Versions are PHP 4.4.2-1build1, PEAR-1.4.6, SOAP-0.9.4 running in
Linux (Ubuntu Dapper)
When we have multiple items in the result, all goes well, and I can use
the result straight away (I do some JSON translation afterwards, but
that's beyond the scope of my question).
Multiple result:
Actual XML sent back from webservice (sniffed off the connection):
[snipped headers]
<GetChildCatego riesResult>
<item>
<CategoryId>1 </CategoryId>
<Name>Cultura </Name>
<ParentCategory Id>0</ParentCategoryI d>
</item>
<item>
<CategoryId>2 </CategoryId>
<Name>Autom..ve is</Name>
<ParentCategory Id>0</ParentCategoryI d>
</item>
</GetChildCategor iesResult>
[snipped trailing markup]
How PEAR::SOAP translates:
array(2) {
[0]=>
object(stdClass )(3) {
["CategoryId "]=>
string(1) "1"
["Name"]=>
string(7) "Cultura"
["ParentCategory Id"]=>
string(1) "0"
}
[1]=>
object(stdClass )(3) {
["CategoryId "]=>
string(1) "2"
["Name"]=>
string(11) "Automóveis "
["ParentCategory Id"]=>
string(1) "0"
}
}
When I get a single item in the result, however, things go a little
differently - and I'd have to write some pretty silly code to be able
to actually use it "as is":
Single result:
Actual XML sent back from webservice (sniffed off the connection):
[snipped headers]
<GetChildCatego riesResult>
<item>
<CategoryId>3 </CategoryId>
<Name>Carros</Name>
<ParentCategory Id>2</ParentCategoryI d>
</item>
</GetChildCategor iesResult>
[snipped trailing markup]
How PEAR::SOAP translates it:
object(stdClass )(1) {
["item"]=>
&object(stdClas s)(3) {
["CategoryId "]=>
string(1) "3"
["Name"]=>
string(6) "Carros"
["ParentCategory Id"]=>
string(1) "2"
}
}
As you can see, instead of an array of length one, I get an object with
an "item" property, with the expected object inside it. That's not (for
me, at least) the desired behaviour for the beast - is this a bug, a
miss-feature? Or is it supposed to work like that, and I have to write
a work-around for my purposes? Does anyone know of an already-written
workaround?
Thanks in advance for your time,
WageMage / Manuel
when the number of results is one or more than one.
Versions are PHP 4.4.2-1build1, PEAR-1.4.6, SOAP-0.9.4 running in
Linux (Ubuntu Dapper)
When we have multiple items in the result, all goes well, and I can use
the result straight away (I do some JSON translation afterwards, but
that's beyond the scope of my question).
Multiple result:
Actual XML sent back from webservice (sniffed off the connection):
[snipped headers]
<GetChildCatego riesResult>
<item>
<CategoryId>1 </CategoryId>
<Name>Cultura </Name>
<ParentCategory Id>0</ParentCategoryI d>
</item>
<item>
<CategoryId>2 </CategoryId>
<Name>Autom..ve is</Name>
<ParentCategory Id>0</ParentCategoryI d>
</item>
</GetChildCategor iesResult>
[snipped trailing markup]
How PEAR::SOAP translates:
array(2) {
[0]=>
object(stdClass )(3) {
["CategoryId "]=>
string(1) "1"
["Name"]=>
string(7) "Cultura"
["ParentCategory Id"]=>
string(1) "0"
}
[1]=>
object(stdClass )(3) {
["CategoryId "]=>
string(1) "2"
["Name"]=>
string(11) "Automóveis "
["ParentCategory Id"]=>
string(1) "0"
}
}
When I get a single item in the result, however, things go a little
differently - and I'd have to write some pretty silly code to be able
to actually use it "as is":
Single result:
Actual XML sent back from webservice (sniffed off the connection):
[snipped headers]
<GetChildCatego riesResult>
<item>
<CategoryId>3 </CategoryId>
<Name>Carros</Name>
<ParentCategory Id>2</ParentCategoryI d>
</item>
</GetChildCategor iesResult>
[snipped trailing markup]
How PEAR::SOAP translates it:
object(stdClass )(1) {
["item"]=>
&object(stdClas s)(3) {
["CategoryId "]=>
string(1) "3"
["Name"]=>
string(6) "Carros"
["ParentCategory Id"]=>
string(1) "2"
}
}
As you can see, instead of an array of length one, I get an object with
an "item" property, with the expected object inside it. That's not (for
me, at least) the desired behaviour for the beast - is this a bug, a
miss-feature? Or is it supposed to work like that, and I have to write
a work-around for my purposes? Does anyone know of an already-written
workaround?
Thanks in advance for your time,
WageMage / Manuel