PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Web Services » SOAP » Bug #2627

Array in return object was not parsed correctly

Details

Submitted2004-10-27 00:32 UTC
Fromsong dot qiu at tumbleweed dot com
Assignedcweiske
StatusClosed
PackageSOAP
PHP Version4.2.2
OSRedhat 8.0
Roadmaps(Not assigned)

Comments

[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>