Array problems with SOAP and PHP – Updated

Please see my new blog


This is a followup 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:

$x = new SoapClient($wsdl, array(‘features’ => SOAP_SINGLE_ELEMENT_ARRAYS));

Related articles:

About these ads

8 Comments

  1. Balu said,

    March 13, 2008 at 10:20 am

    *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. eirikhoem said,

    March 13, 2008 at 10:29 am

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

  3. James Morris said,

    March 13, 2008 at 11:59 am

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

  4. Lukas said,

    March 13, 2008 at 1:33 pm

    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. March 13, 2008 at 4:00 pm

    [...] Hoem has posted an update on a previous problem he was having when working with SOAP in PHP and its handling of arrays. The [...]

  6. Matt said,

    March 13, 2008 at 6:43 pm

    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?

  7. Matt said,

    March 13, 2008 at 6:44 pm

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

  8. March 17, 2008 at 5:48 pm

    [...] Array problems with SOAP and PHP – Updated Category: PHP, SOAP, Tips, X-Fire [...]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: