views:

90

answers:

1

I'm consuming a web service in PHP. If the service returns 2 or more records the object comes back as an array. However, if I call the same service that returns 1 record, the object is not an array. This makes for some messy logic having to watch for both cases when one would think PHP could be smart enough to handle this appropriately and always return an array of 1 element.

So my question is - is there a way to force the return object to always be an array? Some property in the call or something?

EDIT

I'm using PHP's soapclient library. The service is an in-house one that returns an array of a custom class.

+2  A: 

Hi,

you could try the following:

$client = new SoapClient("http://host/services/some.wsdl", 
array('feature' => SOAP_SINGLE_ELEMENT_ARRAYS));

This should make php behave the way you want.

Also you might find this dotvoid article interesting.

HTH

KB22
Unfortunately this has no effect on my result. A quick google shows a number of other people that have the same problem. Perhaps it's really a PHP bug?
Chu
pls post your client code, and the relevant WSDL snippet (if available)
KB22