From: php at atis dot id dot lv
Operating system: Linux 2.6.24.7-92.fc8 x86_64
PHP version: 5.2.9
PHP Bug Type: XMLRPC-EPI related
Bug description: Can't encode struct with integer name
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 bug report at http://bugs.php.net/?id=48028&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=48028&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=48028&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=48028&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=48028&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=48028&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=48028&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=48028&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=48028&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=48028&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=48028&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=48028&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=48028&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=48028&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=48028&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48028&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=48028&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=48028&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=48028&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=48028&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=48028&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=48028&r=mysqlcfg