From: David D. <Dav...@su...> - 2005-01-26 16:58:55
|
I have a questions about how NuSOAP treats the $return value of the = call() method if it is an array. Right now (in CVS 1.82) we have this: if(is_array($return)){ // multiple 'out' parameters if(sizeof($return) > 1){ return $return; } // single 'out' parameter return array_shift($return); // nothing returned (ie, echoVoid) } else { return ""; } My question is about the appropriateness of calling array_shift on the = $return variable in all cases where $return has only 1 element. In the service I am using, I sometimes receive a <Status> element along = with an attribute in the root element. This results in a $return array = with two elements, the first a string containing the attribute result, = the second is an array called 'Status' with the <Status> data in it. It seems possible though, in this service, that the root element = attribute is sometimes not present and this is where I am seeing a = problem. In that case, the $return array (before it gets to the code I = have pasted above) contains a single array called 'Status' with the = <Status> data in it. Just like the paragraph above except with no = second array element containing the root element attribute, because it = wasn't in the response. Because of the array_shift, I am having to look for this Status = information in two places. =20 The first case results in an 'untouched' array that I can reference = like: $results['Status']['!code'] The second case puts the elements that I would have expected in a = 'Status' array element in the root element, because of the array_shift = call, and I have to look for it here: $results['!code'] Is this the expected behavior? And if so is there some rationale behind = it? If it is not expected, I have a proposed solution, which works for me, = but I wanted to ask for comments. Particularly, is this something that = is going to screw up a lot of legacy code? // array of return values if(is_array($return)){ // multiple 'out' parameters reset($return); /**** only added this line ****/ if((sizeof($return) > 1) || is_array(current($return))){ /**** only = changed this line ****/ return $return; } =09 // single 'out' parameter return array_shift($return); // nothing returned (ie, echoVoid) } else { return ""; } In my solution, it will only do the array_shift if that single element = is not an array. If it is an array it will return it and maintain the = structure. Thanks in advance for any help or comments and for reading my long = message :) -David Derr |