summaryrefslogtreecommitdiff
path: root/includes/xmlrpc.inc
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2005-10-28 13:13:30 +0000
committerDries Buytaert <dries@buytaert.net>2005-10-28 13:13:30 +0000
commit699df6742b36a28594c37044295447fc790ed218 (patch)
tree551464eaf214671ae787e47507f6853c44480254 /includes/xmlrpc.inc
parenta3e47f1e44f9ae33b8302f7b8b14c6863353a271 (diff)
downloadbrdo-699df6742b36a28594c37044295447fc790ed218.tar.gz
brdo-699df6742b36a28594c37044295447fc790ed218.tar.bz2
- Patch #34214 by ax:
* xmlrpc_value_calculate_type() fails for empty arrays * PHPDoc for xmlrpc_value_calculate_type() * use is_*() instead of gettype() as advised in the PHP manual (and document this) * coding style
Diffstat (limited to 'includes/xmlrpc.inc')
-rw-r--r--includes/xmlrpc.inc52
1 files changed, 34 insertions, 18 deletions
diff --git a/includes/xmlrpc.inc b/includes/xmlrpc.inc
index a31d53e11..e2216e7e6 100644
--- a/includes/xmlrpc.inc
+++ b/includes/xmlrpc.inc
@@ -30,27 +30,43 @@ function xmlrpc_value($data, $type = FALSE) {
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) {