|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-04-21 08:26 UTC] jani@php.net
[2009-04-21 10:07 UTC] php at atis dot id dot lv
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 11:00:02 2025 UTC |
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>