Issues

ZF-10914: Zend_XmlRpc_Value converts Integer to String param

Description

Yesterday I've updated ZF from 1.11.1 to 1.11.2 and today morning got some errors with Zend_XmlRpc_Client.

I have remote XML-RPC server that has one of following methods signature:


simulator.copySetupDevices(String dstIp, Integer dstPort, String setupName, String options)

I was using this code to communicate with it:

 
$client = new Zend_XmlRpc_Client($connectUrl);
$params = array('10.10.1.1', 9999, 'TestReload3', '{}');
$client->call('simulator.copySetupDevices', $params);

Until 1.11.2 it worked fine. But after upgrade I got an exception


No method matching arguments: java.lang.String, java.lang.String, java.lang.String, java.lang.String

I see from here that while passing second argument as PHP Integer, it was converted in ZF to String somewhere.

Debugging the code I found that problem in {{Zend_XmlRpc_Value::getXmlRpcValue()}}.

Auto-detecting type done via


Zend_XmlRpc_Value::_phpVarToNativeXmlRpc($value)

On line 318 we got switch that returns 'int' for our '(int) 9999'.


switch (self::getXmlRpcTypeByValue($value))

That's fine, but switch's case for Integers is {{case 'integer':}} (@line 349), so we bypass it and goto the {{default:}} which is


return new Zend_XmlRpc_Value_String($value)

In ZF 1.11.1 switch was returning 'integer' for Integers because of {{gettype()}}


switch (gettype($value))

I think Matthew missed this when committed new Zend/XmlRpc/Value.php


@version    $Id: Value.php 23584 2010-12-28 19:51:49Z matthew $

Proposed solution - change to


case self::XMLRPC_TYPE_INTEGER:

or

case self::XMLRPC_TYPE_INTEGER:
case 'integer':

Comments

better formatting

Meanwhile workaround is to use Zend_XmlRpc_Value_* class


$client = new Zend_XmlRpc_Client($connectUrl);

$params = array(
  '10.10.1.1',
  new Zend_XmlRpc_Value_Integer(9999),
  'TestReload3',
  '{}',
);

$client->call('simulator.copySetupDevices', $params);

It goes further than just integers.

The Zend_XmlRpc_Value class also appears to have done away with the struct type. So associative arrays are converted to strings too. Note the _phpVarToNativeXmlRpc method and how it is missing a case for 'struct' in the switch statement

switch (self::getXmlRpcTypeByValue($value))

line 318

There is an array type, but no struct type even though the array case very explicitly shows Struct code.

The merge r23584 incomplete fixed with r23624 - thanks.