Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.14.0

Bug #2627 Array in return object was not parsed correctly
Submitted: 2004-10-27 00:32 UTC
From: song dot qiu at tumbleweed dot com Assigned: cweiske
Status: Closed Package: SOAP
PHP Version: 4.2.2 OS: Redhat 8.0
Roadmaps: (Not assigned)    
Comments Add Comment Add patch

Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem : 22 + 14 = ?

 [2004-10-27 00:32 UTC] song dot qiu at tumbleweed dot com
Description: ------------ I have a PEAR:SOAP client to call a SOAP sever to get an object which suppose to contain two array of objects. But I just got the first array right. The second array becomes the object which is the last element of the second array. However, in the trace information, I did see two arrays being returned in xml format which means PEAR:SOAP did not parse this xml response correctly. Reproduce code: --------------- $incoming_entries = array(); $outgoing_entries = array(); $soapclient = new SOAP_Client('http://localhost:8085'); $messageTraceLog = $soapclient->call("getMessageTraceLog", $v=array('messageId'=>$msg_id), array('namespace'=>'urn:MailGate', 'soapaction'=>'', 'style'=>'rpc', 'use'=>'encoded')); $incoming_entries = $messageTraceLog['incoTraceEntries']; $outgoing_entries = array(); $outgoing_entries[0] = $messageTraceLog['outgTraceEntries']; Expected result: ---------------- $messageTraceLog['outgTraceEntries']; should be an array instead of a single object Actual result: -------------- $messageTraceLog['outgTraceEntries'] is a single object.


 [2005-02-23 17:12 UTC] bruce dot drummond at tribalinternet dot co dot uk
I have a similar problem: My return xml looks like this: <Activities diffgr:id="Activities1" msdata:rowOrder="0"> <field1>val1</field1> <field2>val1</field2> </Activities> <Activities diffgr:id="Activities2" msdata:rowOrder="1"> <field1>val2</field1> <field2>val2</field2 </Activities> <Activities diffgr:id="Activities3" msdata:rowOrder="2"> <field1>val3</field1> <field2>val3</field2 </Activities> And yet the Soap response is just [Activities] => stdClass Object ( [field1] => val3 [field2] => val3 ) Like it is overwriting each array element instead of appending it to the array. However what seems strange is there are multiple arrays and it always manages to correctly parse the first one, and then fails on all the rest. Any word on how to get around this?
 [2005-11-27 00:09 UTC] park at redsummit dot com
The problem is that the $isstruct flag is not reset after processing the first array. I have a work around that is not very elegant, but it works. There are 3 changes in the section of code below, beginning around line 889 in SOAP/Base.php. It should be noted that this bug is not OS specific. <pre> $counter = 1; $testname = ""; // NEW CODE - 1 LINE $isstruct = !$SOAP_OBJECT_STRUCT || !is_array($return); foreach ($soapval->value as $item) { if (is_object($return)) { // NEW CODE - 3 LINES if ($testname != $item->name) { $isstruct = !$SOAP_OBJECT_STRUCT || !is_array($return); $testname = ""; } // END OF NEW CODE if ($this->_wsdl) { // Get this child's WSDL information. // /$soapval->ns/$soapval->type/$item->ns/$item->name $child_type = $this->_wsdl->getComplexTypeChildType( $soapval->namespace, $soapval->name, $item->namespace, $item->name); if ($child_type) { $item->type = $child_type; } } if (!$isstruct || $item->type == 'Array') { if (isset($return->{$item->name}) && is_object($return->{$item->name})) { $return->{$item->name} =& $this->_decode($item); } elseif (isset($return->{$item->name}) && is_array($return->{$item->name})) { $return->{$item->name}[] =& $this->_decode($item); } elseif (is_array($return)) { $return[] =& $this->_decode($item); } else { $return->{$item->name} =& $this->_decode($item); } } elseif (isset($return->{$item->name})) { $isstruct = false; $testname = $item->name; // NEW CODE - 1 LINE if (count(get_object_vars($return)) == 1) { $d =& $this->_decode($item); $return = array($return->{$item->name}, $d); } else { $d =& $this->_decode($item); $return->{$item->name} = array($return->{$item->name}, $d); } } else { $return->{$item->name} =& $this->_decode($item); } </pre>
 [2007-06-07 15:49 UTC] jcv (Javier Correa)
I still got this problem, used park's solution but the second array still get miss parsed. I post the SOAP response and the resulting php object. <env:Envelope xmlns:env=''> <env:Header/> <env:Body> <ns2:viewTaskResponse xmlns:ns2=''> <return> <tiid>1131</tiid> <taskName>Rellenar Datos</taskName> <formName>Rellenar-Datos.xhtml</formName> <transitions>Reemplazo lector</transitions> <transitions>Nuevo lector</transitions> <requieredParameters>codigo lugar</requieredParameters> <requieredParameters>nombre lugar</requieredParameters> <requieredParameters>glosa</requieredParameters> <requieredParameters>responsable</requieredParameters> </return> </ns2:viewTaskResponse> </env:Body> </env:Envelope> stdClass Object ( [tiid] => 1131 [taskName] => Rellenar Datos [formName] => Rellenar-Datos.xhtml [transitions] => Array ( [0] => Reemplazo lector [1] => Nuevo lector ) [requieredParameters] => Array ( [0] => Array ( [0] => Array ( [0] => codigo lugar [1] => nombre lugar ) [1] => glosa ) [1] => responsable ) )
 [2007-06-27 08:23 UTC] cweiske (Christian Weiske)
Bruce, your xml is invalid - the closing > for the field tags are missing.
 [2007-06-27 08:31 UTC] cweiske (Christian Weiske)
The second array has only one value, trying to fix this.
 [2007-06-27 13:28 UTC] cweiske (Christian Weiske)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on by the end of next Sunday (CET). If this was a problem with the website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.
 [2008-07-17 10:06 UTC] zhiivn (Khoa Nguyen)
I also got the same problem like Javier Correa. I always received the nested array when receiving the multiple elements respone. Is the bug fixed? I used the latest release, but I still got the problem.