Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#1 Support structs and arrays in encoding correctly

closed
nobody
5
2014-08-16
2005-08-04
James
No

PHP doesn't natively know the difference between
associative arrays (read : hashes in Perl) and numeric
arrays (read : arrays in Perl).

The current encode function turns PHP array types into
XMLRPC array types even if they are required to be
XMLRPC structs

I've used the following code to fix this, I've seen
some other implementations of this so mine is by no
means the only way to do this.

$foundIntKey is just a simple incrementer that counts
the number of numeric keys in the $php_val
array/object. After array traversal is complete, a
comparison is made to determine if all the array keys
are numeric, if so the xml rpc data type is array, else
the data type is struct.

Cheers
James


function xmlrpc_encode($php_val)

  case 'array':
  case 'object':
                            $arr = array();

//$xmlrpcArray/$xmlrpcStruct handling
$foundIntKey = 0;
while (list($k,$v) =
each($php_val))
{
if(is_int($k))
{
$foundIntKey++;
}
$arr[$k] =
php_xmlrpc_encode($v);
}
//determine if all the
keys were ints..
if($foundIntKey ==
count($php_val))
{

$xmlrpc_val->addArray($arr);
}
else
{

$xmlrpc_val->addStruct($arr);
}

    break;

Discussion

  • Gaetano Giunta
    Gaetano Giunta
    2005-09-04

    Logged In: YES
    user_id=114789

    This is already implemented in CVS. Could you please test
    that version?

     


Anonymous


Cancel   Add attachments