xmlrpc_value_calculate_type

Versions
4.6 – 6
xmlrpc_value_calculate_type(&$xmlrpc_value)
7
xmlrpc_value_calculate_type($xmlrpc_value)

Map PHP type to XML-RPC type.

see http://www.xmlrpc.com/spec#scalars

Parameters

$xmlrpc_value Variable whose type should be mapped.

Return value

XML-RPC type as string.

▾ 1 function calls xmlrpc_value_calculate_type()

xmlrpc_value in includes/xmlrpc.inc
Recursively turn a data structure into objects with 'data' and 'type' attributes.

Code

includes/xmlrpc.inc, line 53

<?php
function xmlrpc_value_calculate_type(&$xmlrpc_value) {
  // 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';
  }
  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';
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.