You are here: Pear SOAP oddity « PHP Programming Language « IT news, forums, messages
Pear SOAP oddity

Posted by wagemage.pt on 05/22/06 14:36

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]

<GetChildCategoriesResult>
<item>
<CategoryId>1</CategoryId>
<Name>Cultura</Name>
<ParentCategoryId>0</ParentCategoryId>
</item>
<item>
<CategoryId>2</CategoryId>
<Name>Autom..veis</Name>
<ParentCategoryId>0</ParentCategoryId>
</item>
</GetChildCategoriesResult>
[snipped trailing markup]

How PEAR::SOAP translates:

array(2) {
[0]=>
object(stdClass)(3) {
["CategoryId"]=>
string(1) "1"
["Name"]=>
string(7) "Cultura"
["ParentCategoryId"]=>
string(1) "0"
}
[1]=>
object(stdClass)(3) {
["CategoryId"]=>
string(1) "2"
["Name"]=>
string(11) "Automóveis"
["ParentCategoryId"]=>
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]
<GetChildCategoriesResult>
<item>
<CategoryId>3</CategoryId>
<Name>Carros</Name>
<ParentCategoryId>2</ParentCategoryId>
</item>
</GetChildCategoriesResult>
[snipped trailing markup]

How PEAR::SOAP translates it:

object(stdClass)(1) {
["item"]=>
&object(stdClass)(3) {
["CategoryId"]=>
string(1) "3"
["Name"]=>
string(6) "Carros"
["ParentCategoryId"]=>
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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация