ID:               48028
 Updated by:       [email protected]
 Reported By:      php at atis dot id dot lv
-Status:           Open
+Status:           Bogus
 Bug Type:         XMLRPC-EPI related
 Operating System: Linux 2.6.24.7-92.fc8 x86_64
 PHP Version:      5.2.9
 New Comment:

Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

Same as bug #37746


Previous Comments:
------------------------------------------------------------------------

[2009-04-20 16:26:42] php at atis dot id dot lv

Description:
------------
It is impossible to generate <struct> responses from associative arrays
with numeric and non-zero-based keys.

I was hoping to see either:

* php string keys are converted to <struct> even if they have numeric
value. 
Example: array('123'=>'abc') becomes 

<struct><name>123</name><value>abc</value></struct>

* all non-zero-based and non-sequential array keys are converted to
<struct>.

For example:

array('a','b','c') becomes:
<array><value>a</value><value>b</value><value>c</value></array>

array('a',3=>'b','5'=>'c') becomes:
<struct>
  <name>0</name><value>a</value>
  <name>3</name><value>b</value>
  <name>5</name><value>c</value>
</struct>

* output option that would automatically convert all arrays to <struct>
type. 

I was looking into extension source, and found that within
determine_vector_type and PHP_to_XMLRPC_worker a variable and test with
simple 0 based index should be simple enough, however somehow
zend_hash_get_current_key doesn't detect the initial type of array key
correctly. Of course converting it to *char would be possible, but i'm
not sure if it's the correct way.


Workarounds found in comments of bug #37746 is to process return array
in recursive way and add chr(0) at end of each numeric key, but that is
ugly and slow. Example for workaround:

  function xmlrpc_fix_numeric_keys($data) {
    $result = array();
    if (!is_array($data)) return $data;
    foreach ($data as $k=>$v) {
      if (is_numeric($k)) $k=$k.chr(0);
      $result[$k]=xmlrpc_fix_numeric_keys($v);
    }
    return $result;
  }



Reproduce code:
---------------
  $test = array('333'=>'ddd','9212'=>'asd');
  $rpc = xmlrpc_encode($test);
  echo $rpc;



Expected result:
----------------
<?xml version="1.0" encoding="utf-8"?>
<params>
<param>
 <value>
  <struct>
   <member>
    <name>333</name>
    <value>
     <string>ddd</string>
    </value>
   </member>
   <member>
    <name>9212</name>
    <value>
     <string>asd</string>
    </value>
   </member>
  </struct>
 </value>
</param>
</params>


Actual result:
--------------
<?xml version="1.0" encoding="utf-8"?>
<params>
<param>
 <value>
  <array>
   <data>
    <value>
     <string>ddd</string>
    </value>
    <value>
     <string>asd</string>
    </value>
   </data>
  </array>
 </value>
</param>
</params>


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=48028&edit=1

Reply via email to