php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50285 xmlrpc does not preserve keys in encoded indexed arrays
Submitted: 2009-11-24 14:55 UTC Modified: 2009-11-25 02:03 UTC
From: tony at marston-home dot demon dot co dot uk Assigned: felipe (profile)
Status: Closed Package: XMLRPC-EPI related
PHP Version: 5.*, 6 OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tony at marston-home dot demon dot co dot uk
New email:
PHP Version: OS:

 

 [2009-11-24 14:55 UTC] tony at marston-home dot demon dot co dot uk
Description:
------------
When the method called in xmlrpc_server_call_method() returns an array where the keys are numeric but non-sequential it does not include the keys in the xml response, so when that response is decoded by the client all the keys are resequenced from zero. This means that all the original keys are lost.

Reproduce code:
---------------
function indexedArray ( $func, $params) {
    return array(1=>'One', 3=>'Three', 5=>'Five');
} // indexedArray
$server = xmlrpc_server_create();
$result = xmlrpc_server_register_method($server, 'indexedArray', 'indexedArray');
$HTTP_RAW_POST_DATA = <<<EOD
<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>indexedArray</methodName>
<params />
</methodCall>
EOD;
$response = xmlrpc_server_call_method($server, $HTTP_RAW_POST_DATA, null);
$array = xmlrpc_decode($response);

Expected result:
----------------
The contents of $array should read (1=>'One', 3=>'Three', 5=>'Five'). This is because the xml document does not contain any <name> elements for each <member>.

Actual result:
--------------
The contents of $array is (0=>'One', 1=>'Three', 2=>'Five')

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-24 20:16 UTC] jani@php.net
A little bit simpler test which shows the same issue:

<?php

$a = array(1 => 'one', 3 => 'three', 5 => 'five', 'a'=> 'foo');
var_dump($a, xmlrpc_encode($a));

/* xmlrpc_decode() does work when passed proper data: */
$r = '<?xml version="1.0" encoding="utf-8"?>
<params>
<param>
 <value>
  <struct>
   <member>
    <name>1</name>
    <value>
     <string>one</string>
    </value>
   </member>
   <member>
    <name>3</name>
    <value>
     <string>three</string>
    </value>
   </member>
   <member>
    <name>5</name>
    <value>
     <string>five</string>
    </value>
   </member>
   <member>
    <name>a</name>
    <value>
     <string>foo</string>
    </value>
   </member>
  </struct>
 </value>
</param>
</params>
';

var_dump(xmlrpc_decode($r));

?>

 [2009-11-25 02:03 UTC] svn@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&revision=291285
Log: - Fixed bug #50285 (xmlrpc does not preserve keys in encoded indexed arrays)
 [2009-11-25 02:03 UTC] felipe@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC