Index: includes/xmlrpc.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/xmlrpc.inc,v retrieving revision 1.25 diff -F^f -u -r1.25 xmlrpc.inc --- includes/xmlrpc.inc 10 Oct 2005 09:03:11 -0000 1.25 +++ includes/xmlrpc.inc 16 Oct 2005 12:37:39 -0000 @@ -30,27 +30,43 @@ function xmlrpc_value($data, $type = FAL return $xmlrpc_value; } +/** + * Map PHP type to XML-RPC type. + * + * @param $xmlrpc_value + * Variable whose type should be mapped. + * @return + * XML-RPC type as string. + * @see + * http://www.xmlrpc.com/spec#scalars + */ function xmlrpc_value_calculate_type(&$xmlrpc_value) { - $type = gettype($xmlrpc_value->data); - switch ($type) { - case 'boolean': case 'double': - return $type; - case 'integer': + // http://www.php.net/gettype: Never use gettype() to test for a certain type [...] Instead, use the is_* functions. + if (is_bool($xmlrpc_value->data)) { + return 'boolean'; + } + if (is_double($xmlrpc_value->data)) { + return 'double'; + } + if (is_int($xmlrpc_value->data)) { return 'int'; - case 'array': - return range(0, count($xmlrpc_value->data) - 1) === array_keys($xmlrpc_value->data) ? 'array' : 'struct'; - case 'object': - if ($xmlrpc_value->data->is_date) { - return 'date'; - } - if ($xmlrpc_value->data->is_base64) { - return 'base64'; - } - $xmlrpc_value->data = get_object_vars($xmlrpc_value->data); - return 'struct'; - default: - return 'string'; } + if (is_array($xmlrpc_value->data)) { + // empty or integer-indexed arrays are 'array', string-indexed arrays 'struct' + return empty($xmlrpc_value->data) || range(0, count($xmlrpc_value->data) - 1) === array_keys($xmlrpc_value->data) ? 'array' : 'struct'; + } + if (is_object($xmlrpc_value->data)) { + if ($xmlrpc_value->data->is_date) { + return 'date'; + } + if ($xmlrpc_value->data->is_base64) { + return 'base64'; + } + $xmlrpc_value->data = get_object_vars($xmlrpc_value->data); + return 'struct'; + } + // default + return 'string'; } function xmlrpc_value_get_xml($xmlrpc_value) { @@ -232,11 +248,13 @@ function xmlrpc_message_tag_close($parse if ($xmlrpc_message->array_structs_types[count($xmlrpc_message->array_structs_types)-1] == 'struct') { // Add to struct $xmlrpc_message->array_structs [count($xmlrpc_message->array_structs )-1][$xmlrpc_message->current_struct_name[count($xmlrpc_message->current_struct_name)-1]] = $value; - } else { + } + else { // Add to array $xmlrpc_message->array_structs [count($xmlrpc_message->array_structs )-1][] = $value; } - } else { + } + else { // Just add as a paramater $xmlrpc_message->params[] = $value; }