Some remote method calls require parameters. These are given to
the call() method of Zend_XmlRpc_Client
as an array in the second parameter. Each parameter may be
given as either a native PHP type which will be automatically
converted, or as an object representing a specific XML-RPC type
(one of the Zend_XmlRpc_Value objects).
Parameters may be passed to call() as native
PHP variables, meaning as a String,
Integer, Float,
Boolean, Array, or an
Object. In this case, each PHP native type will
be auto-detected and converted into one of the XML-RPC types
according to this table:
Table 170. PHP and XML-RPC Type Conversions
| PHP Native Type | XML-RPC Type |
|---|---|
| integer | int |
| Zend_Crypt_Math_BigInteger | i8 |
| double | double |
| boolean | boolean |
| string | string |
| null | nil |
| array | array |
| associative array | struct |
| object | array |
| Zend_Date | dateTime.iso8601 |
| DateTime | dateTime.iso8601 |
What type do empty arrays get cast to?
Passing an empty array to an XML-RPC method is problematic,
as it could represent either an array or a struct.
Zend_XmlRpc_Client detects such conditions and
makes a request to the server's
system.methodSignature method to determine the
appropriate XML-RPC type to cast to.
However, this in itself can lead to issues. First off,
servers that do not support
system.methodSignature will log failed
requests, and Zend_XmlRpc_Client will resort to
casting the value to an XML-RPC array type. Additionally,
this means that any call with array arguments will result in
an additional call to the remote server.
To disable the lookup entirely, you can call the
setSkipSystemLookup() method prior to making
your XML-RPC call:
<?php
$client->setSkipSystemLookup(true);
$result = $client->call('foo.bar', array(array()));
Parameters may also be created as Zend_XmlRpc_Value
instances to specify an exact XML-RPC type. The primary reasons
for doing this are:
When you want to make sure the correct parameter type is passed to the procedure (i.e. the procedure requires an integer and you may get it from a database as a string)
When the procedure requires base64 or dateTime.iso8601 type (which doesn't exists as a PHP native type)
When auto-conversion may fail (i.e. you want to pass an empty XML-RPC struct as a parameter. Empty structs are represented as empty arrays in PHP but, if you give an empty array as a parameter it will be auto-converted to an XML-RPC array since it's not an associative array)
There are two ways to create a Zend_XmlRpc_Value
object: instantiate one of the Zend_XmlRpc_Value
subclasses directly, or use the static factory method
Zend_XmlRpc_Value::getXmlRpcValue().
Table 171. Zend_XmlRpc_Value Objects for XML-RPC Types
| XML-RPC Type |
Zend_XmlRpc_Value Constant |
Zend_XmlRpc_Value Object |
|---|---|---|
| int |
Zend_XmlRpc_Value::XMLRPC_TYPE_INTEGER
|
Zend_XmlRpc_Value_Integer |
| i8 |
Zend_XmlRpc_Value::XMLRPC_TYPE_I8
|
Zend_XmlRpc_Value_BigInteger |
| ex:i8 |
Zend_XmlRpc_Value::XMLRPC_TYPE_APACHEI8
|
Zend_XmlRpc_Value_BigInteger |
| double |
Zend_XmlRpc_Value::XMLRPC_TYPE_DOUBLE
|
Zend_XmlRpc_Value_Double |
| boolean |
Zend_XmlRpc_Value::XMLRPC_TYPE_BOOLEAN
|
Zend_XmlRpc_Value_Boolean |
| string |
Zend_XmlRpc_Value::XMLRPC_TYPE_STRING
|
Zend_XmlRpc_Value_String |
| nil |
Zend_XmlRpc_Value::XMLRPC_TYPE_NIL
|
Zend_XmlRpc_Value_Nil |
| ex:nil |
Zend_XmlRpc_Value::XMLRPC_TYPE_APACHENIL
|
Zend_XmlRpc_Value_Nil |
| base64 |
Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64
|
Zend_XmlRpc_Value_Base64 |
| dateTime.iso8601 |
Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME
|
Zend_XmlRpc_Value_DateTime |
| array |
Zend_XmlRpc_Value::XMLRPC_TYPE_ARRAY
|
Zend_XmlRpc_Value_Array |
| struct |
Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT
|
Zend_XmlRpc_Value_Struct |
Automatic Conversion
When building a new Zend_XmlRpc_Value
object, its value is set by a PHP type. The
PHP type will be converted to the specified type using
PHP casting. For example, if a string is given as a
value to the Zend_XmlRpc_Value_Integer
object, it will be converted using
(int)$value.




