Array problems with SOAP and PHP – Updated


This is a follow up to my post about array problems with SOAP and PHP. The scenario was that when an array with only one object was returned over SOAP the array was discarded and pointed straight to the single object.

Cmm was kind enough to tip me this PHP bug report, which explains that this is actually not a bug, but a feature.

To get arrays containing one single element, simply create the SoapClient as follows:

1
$x = new SoapClient($wsdl, array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));

Related articles:

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • description
  • Live
  • Slashdot
  1. #1 by Balu - March 13th, 2008 at 10:20

    *Gna*, this post a few days ago would’ve really helped me :)

    I tried to work around that problem by

    if (!is_array($something)) $something = array($something);

    I think I better check the options next time…

  2. #2 by eirikhoem - March 13th, 2008 at 10:29

    Yeah, the code I’m running now has quite a few hacks like that. Feels good to be able to clean it up :)

  3. #3 by James Morris - March 13th, 2008 at 11:59

    This is a usefull GOTCHA that i’ll be implementing soon.

  4. #4 by Lukas - March 13th, 2008 at 13:33

    Not sure if that bug is finally fixed, but the mode you mention used to turn NULL into array(NULL), which is also not what you really expect imho.

  5. #5 by Matt - March 13th, 2008 at 18:43

    Wow, wish i would have known this 6 months ago. Did all sorts of hacks to get around that. My question is… where is this documented?

  6. #6 by Matt - March 13th, 2008 at 18:44

    By the way when using soap has anyone seen php segfaults when the other end doesn’t respond?

(will not be published)