|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48028 Can't encode struct with integer name
Submitted: 2009-04-20 16:26 UTC Modified: 2009-04-21 10:07 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: php at atis dot id dot lv Assigned:
Status: Not a bug Package: XMLRPC-EPI related
PHP Version: 5.2.9 OS: Linux x86_64
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: php at atis dot id dot lv
New email:
PHP Version: OS:


 [2009-04-20 16:26 UTC] php at atis dot id dot lv
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 


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

For example:

array('a','b','c') becomes:

array('a',3=>'b','5'=>'c') becomes:

* 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);
    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"?>

Actual result:
<?xml version="1.0" encoding="utf-8"?>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-21 08:26 UTC]
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
 [2009-04-21 10:07 UTC] php at atis dot id dot lv
I was unable to comment it, but I have feeling that You don't understand the point.

XMLRPC-EPI doesn't allow to encode <struct> with numbers in name field. This is possible in other implementations I have worked with, and the appending char(0) method is a hack that might break.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Oct 07 19:05:53 2022 UTC