note 91821 added to soapclient.soapcall

From: Date: Fri, 26 Jun 2009 16:56:45 +0000
Subject: note 91821 added to soapclient.soapcall
Groups: php.notes 
Request: Send a blank email to php-notes+get-157553@lists.php.net to get a copy of this message
I see notes from lot of users where they wanted to convert the response to an array. Problem description as told by one of the user: -------------------------------------------------------- When a SOAP call returns an array [max_elements=">1"] - you may not actually get an array... (this may be a fault in the wsdl, but it's certainly a potential headache). foreach($result->field as $field) { doSomethingWith($field); } With more than 1 <field>, you'll loop through the <field> tags (as expected)... However, with exactly 1 <field>, you'll instead loop through the child elements of the first <field> (almost certainly *not* what you wanted to happen)... Solution: ----------- Use SoapClient features option: new SoapClient($wsdl, array("features" => SOAP_SINGLE_ELEMENT_ARRAYS); and then the PHP takes care of converting result to an array. I have been bitten by this before and never looked into this option ...duh...duh ---- Server IP: 209.41.74.194 Probable Submitter: 199.72.20.100 ---- Manual Page -- http://www.php.net/manual/en/soapclient.soapcall.php Edit -- https://master.php.net/note/edit/91821 Del: integrated -- https://master.php.net/note/delete/91821/integrated Del: useless -- https://master.php.net/note/delete/91821/useless Del: bad code -- https://master.php.net/note/delete/91821/bad+code Del: spam -- https://master.php.net/note/delete/91821/spam Del: non-english -- https://master.php.net/note/delete/91821/non-english Del: in docs -- https://master.php.net/note/delete/91821/in+docs Del: other reasons-- https://master.php.net/note/delete/91821 Reject -- https://master.php.net/note/reject/91821 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#157553) next »