ID: 14782
Updated by: daniel.oconnor@gmail.com
Reported By: gram at roadstarclinic dot com
Summary: logic problem in SOAP_Base bulids multidimensional
arrays instead of flat
Status: Assigned
Type: Bug
Package: SOAP
Operating System: Ububntu 7.10
Package Version: 0.12.0
PHP Version: 5.2.3
Assigned To: yunosh
Roadmap Versions:
New Comment:
clockwerx@clockwerx-desktop:~/SOAP$ patch -p1 < patch-download.php\?
id\=14782\&patch\=fix-decode-array-problem\&revision\=1224083752
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
Index: Base.php
==================================================
=================
--- Base.php (revision 2020)
+++ Base.php (revision 2021)
--------------------------==================================================
=================
--- Base.php (revision 2020)
+++ Base.php (revision 2021)
File to patch: Base.php
patching file Base.php
Hunk #1 FAILED at 823.
1 out of 1 hunk FAILED -- saving rejects to file Base.php.rej
clockwerx@clockwerx-desktop:~/SOAP$ svn revert Base.php
Previous Comments:
------------------------------------------------------------------------
[2008-10-25 02:44:37] doconnor
Thanks Steve!
------------------------------------------------------------------------
[2008-10-15 12:11:51] gram
Test Case (requires amazon web services developer key):
<?php
require_once('SOAP/Client.php');
$params->AWSAccessKeyId = 'replace with AWS Developer Key';
$params->Request->SearchIndex = 'Books';
$params->Request->Keywords = 'yoga';
$params->Request->ResponseGroup = 'Small';
$amazon = new
SOAP_WSDL('http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl');
$asearch = $amazon->getProxy();
$test = $asearch->ItemSearch($params);
echo '<pre>'.print_r($test['Items'],true).'</pre>'
?>
The 'Item' array of the returned 'Items' object is the problem. It
should return a flat array. Instead it returns a multidimensional
array. If I try to put it into a comment here it will be many pages
long. So will summarize here. The 'Item' array is structured like
this:
Element [0][0][0][0][0][0][0][0] = array([all ten returned items])
Element [1][0][0][0][0][0][0] = array([first nine returned items])
Element [2][0][0][0][0][0] = array([first eight returned items])
Element [3][0][0][0][0] = array([first seven returned items])
Element [4][0][0][0] = array([first six returned items])
Element [5][0][0] = array([first five returned items])
Element [6][0] = array([first four returned items])
Element [7] = array([first three returned items])
Element [8] = array([first two returned items])
It should be a flat array with all ten returned item objects in it. If
one the project devs wants to test and does not have an Amazon Web
Services developer key, please send me an email and I will provide mine
for testing.
------------------------------------------------------------------------
[2008-10-15 09:52:11] gram
I can put something together and submit a patch as well. Its a small
patch, so making it compliant with Pear coding standards won't be an
issue.
Give me a couple of days (right in the middle of a big project) and I
will submit a test case as well. I am writing code that depends upon
this and would rather it stay fixed.
Forgive the brevity of my submission. It was late, and I did not want
to blow through the fix without handing off the solution.
Will get right back to you.
------------------------------------------------------------------------
[2008-10-15 08:12:46] doconnor
Steve, I don't suppose you can write a small executable test case that
demonstrates this?
The reason we love that kind of test, and actual patches, is because we
can make sure that when we fix this problem; it stays fixed - or we can
easily back the changes out if it breaks other tests.
Additionally, we all speak PHP; so we understand exactly what you mean
and change better assess the potential changes.
------------------------------------------------------------------------
[2008-10-12 23:10:18] gram
Description:
------------
This is the only SOAP client I have tested that produced this problem.
All others produced flat arrays for this circumstance.
I have several 'Item' tags coming back sequentially in my xml as value
to 'Item' Container tag.
In Base.php line 826 object SOAP_Base method _decode():
$return->{$item->name} = array($return->{$item->name}, $d);
If $return->{$item->name} is already an array, this will end up building
a multidimensional array because this line builds a new array using the
existing value (which could be an array) and the newly decoded object.
Result == array(array($obj, $obj),$obj).
This problem compounds as items are added to this array building
progressively deeper arrays.
I am using this class to process requests from Amazon Associates
Services which will always try to return ten 'Items' as a the value to a
single tags value. I end up with an array that has ten elements in it,
the first is ten levels deep, the second 9 levels deep etc...
I replaced line 826 with:
if(is_array($return->{$item->name})){
$return->{$item->name} =
array_merge($return->{$item->name},array($d));
} else {
$return->{$item->name} =
array($return->{$item->name}, $d);
}
This completely solved the problem, and I have seen no adverse effects
in any other areas of the code.
I do not use the same coding standards that Pear uses, so not attaching
a patch. Also not filling in the remainder of this form as the problem
is self evident. Just wanted to pass it on.
Thanks for the great work folks!
Gram
------------------------------------------------------------------------