|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2006-06-08 14:02 UTC] glideraerobatics at hotmail dot com
 Description:
------------
I've noticed that when a key of a hash begins with a digit between 1 and 9 that the resulting XML-RPC response will contain an empty key.
This array:
$result = array('666' => 'me', '007' => 'Bond');
will be returned as this which is obviously wrong:
<?xml version="1.0" encoding="iso-8859-1"?>
<methodResponse>
<params>
 <param>
  <value>
   <struct>
    <member>
     <name/>
     <value>
      <string>me</string>
     </value>
    </member>
    <member>
     <name>007</name>
     <value>
      <string>bond</string>
     </value>
    </member>
   </struct>
  </value>
 </param>
</params>
</methodResponse>
Clearly the xmlrpc module has correctly detected that the result is a hash and has therefore made a 'struct'. What it didn't do correctly for some strange reason is treat all keys of the hash as strings (they even really are strings - ask gettype()).
Reproduce code:
---------------
function debug_getHash($method_name, $params, $app_data) {
  $key1 = '666';
  $key2 = '007';
  $result = array(
    $key1   => 'key1 is a ' . gettype($key1),
    $key2   => 'key2 is a ' . gettype($key2),
  );
  return $result;
}
xmlrpc_server_register_method($xmlrpc_server, 'debug.getHash', 'debug_getHash');
Expected result:
----------------
<?xml version="1.0" encoding="iso-8859-1"?>
<methodResponse>
<params>
 <param>
  <value>
   <struct>
    <member>
     <name>666</name>
     <value>
      <string>key1 is a string</string>
     </value>
    </member>
    <member>
     <name>007</name>
     <value>
      <string>key2 is a string</string>
     </value>
    </member>
   </struct>
  </value>
 </param>
</params>
</methodResponse>
Actual result:
--------------
<?xml version="1.0" encoding="iso-8859-1"?>
<methodResponse>
<params>
 <param>
  <value>
   <struct>
    <member>
     <name/>
     <value>
      <string>key1 is a string</string>
     </value>
    </member>
    <member>
     <name>007</name>
     <value>
      <string>key2 is a string</string>
     </value>
    </member>
   </struct>
  </value>
 </param>
</params>
</methodResponse>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 16:00:01 2025 UTC | 
Well, 4 years with an unknown amount of people relying on it. mike@honeybadger:~$ cli -r 'var_dump(xmlrpc_get_type(array(123=>123)), xmlrpc_get_type(array("a"=>123)), xmlrpc_get_type(array(123=>123,"a"=>123)));' string(5) "array" string(6) "struct" string(5) "mixed"