PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Web Services » XML_RPC » Bug #6111

XML_RPC_Client gets wrong data types in response values

Details

Submitted2005-11-29 23:55 UTC
Fromdevel at digitalaudiorock dot com
StatusBogus
PackageXML_RPC
PHP Version5.0.5
OSLinux and Windows
Roadmaps(Not assigned)

Comments

[2005-11-29 23:55 UTC] devel at digitalaudiorock dot com

Description:
------------
As of XML_RPC 1.3.3, values received by XML_RPC_Client from a server decoded into the proper data types when using XML_RPC_Decode or the values getval() method. From 1.4.0 forward, these all seem to decode as php strings. Although I logged this for php 5.0.5, it seems true of php 5.0.2 as well as php 4.

Test script:
---------------
<?php

require_once('XML/RPC.php');

$server = 'http://localhost';
$path = '/path/to/server/script';
$method = 'method_that_returns_integer_1';

$t = new XML_RPC_Client($path, $server);
$m = new XML_RPC_Message($method);
$r = $t->send($m);
$v = $r->value();
$dv = XML_RPC_Decode($v);

print "Dump of raw value...\n";
var_dump($v);
print "Dump of decoded value...\n";
var_dump($dv);

?>

Expected result:
----------------
I would expect the dump of the decoded value to be an integer (or whatever type the server returns).

Actual result:
--------------
Dump of raw value...
object(XML_RPC_Value)#3 (2) {
["me"]=>
array(1) {
["int"]=>
string(1) "1"
}
["mytype"]=>
int(1)
}
Dump of decoded value...
string(1) "1"

[2005-11-30 10:17 UTC] devel at digitalaudiorock dot com

For testing you can use the following server url:

http://digitalaudiorock.com/users/tdexter/xmlrpctest.php

...and method name:

getint

...or methodname getdouble, which returns a double 1.333. This also gets decoded as a string.

[2006-02-28 11:52 UTC] jaffe at cs dot huji dot ac dot il

This problem is even worse, since it screws up hash lookups.
Here is a test case:

$xml='<?xml version="1.0" encoding="utf-8"?
><methodResponse><params><param><value><struct><member><name
>123</name><value><string>456</string></value></
member><member><name>hi</name><value><string>there</
string></value></member></struct></value></param></params></
methodResponse>';
$retval = xmlrpc_decode($xml);
print 'var_export whole $retval<br>';
var_export($retval);
while (list($key, $value) = each($retval))
{
print '<br><br>Found key '.$key.'<br>';
$keyExists = array_key_exists($key, $retval);
print 'array_key_exists: ';
var_export($keyExists);
print '<br><br>var_export $retval['.$key.']<br>';
var_export($retval[$key]);
}

In earlier versions the key exists and is retrieved. In
newer versions, it fails.

[2006-04-11 14:55 UTC] devel at digitalaudiorock dot com

I'm a little confused by your reply. Jaffes comment refers to xmlrpc_decode. My original comment refers to XML_RPC_decode, which is in fact in the pear XML_RPC code, and in prior versions did return php integers and floats for the corresponding xmlrpc types.