Re: SOAP proplem -- arrays are returned as objects!!
| From: | Justin Patrin | Date: | Thu, 01 Apr 2004 21:12:29 +0000 |
| Subject: | Re: SOAP proplem -- arrays are returned as objects!! | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-11575@lists.php.net to get a copy of this message | ||
Mike Barber wrote:
I have this function called via SOAP:SOAP automatically makes associative arrays objects when both sending and receiving. It's a bit annoyingm so I've created a simple function: function objToAssoc($obj) { if(is_object($obj)) {function getList($a, $b) {...while ($dbArray) { $myArray[] = $dbArray;...}return $myArray; }So what I expect to have returned is an array (myArray) which contains arrays (dbArray). When the client makes the call, what it gets back is an array of objects! What is going on? I'm new to SOAP, so I may have missed something, but as far as I can tell it should be working!
$arr = get_object_vars($obj);} else {
$arr = $obj;} if(is_array($arr)) {
foreach($arr as $key => $val) {
$arr[$key] = objToAssoc($val);
}
}
return $arr;
}
Just do:
$arr = objToAssoc($obj);
It will recirsuvely go through and make objects into assoc arrays. Of course, if you want objects in there somewhere, this will turn them into arrays too, but you get the idea.
--
paperCrane <Justin Patrin>