PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Web Services » XML_RPC » Bug #1493

XML_RPC_encode for empty array returns "struct" and not "array".

Details

Submitted2004-05-25 13:09 UTC
Frompash_ka at fonbet dot info
Assigneddanielc
StatusClosed
PackageXML_RPC
PHP VersionIrrelevant
OSIrrelevant
Roadmaps(Not assigned)

Comments

[2004-05-25 13:09 UTC] pash_ka at fonbet dot info

Description:
------------
I need to send an array to client.
Sometimes this array is empty.
In this case XML_RPC_encode() doesn't work as expected, and returns struct, and not array.

The code in RPC.php now is
=================
if ($firstkey === 0 && is_int($lastkey) && ($lastkey + 1) == $count) {
=================
I think, it should be sonmething like this
=================
if (($firstkey === null)||($firstkey === 0 && is_int($lastkey) && ($lastkey + 1) == $count)) {
=================

[2004-12-01 00:39 UTC] techtonik at tut dot by

Another patch. Please test this.

--- E:\RPC_olda.php Wed Dec 01 01:05:54 2004
+++ E:\RPC_oldb.php Wed Dec 01 02:37:42 2004
@@ -1133,29 +1133,17 @@

switch ($type) {
case "array":
+ // convert continuous non-associative array to <array> else to <struct>
$keys = array_keys($php_val);
- $count = count($php_val);
- $firstkey = $keys[0];
- $lastkey = $keys[$count - 1];
- if ($firstkey === 0 && is_int($lastkey) && ($lastkey + 1) == $count) {
- $is_continuous = true;
- $expected = 0;
- foreach ($keys as $actual) {
- if ($actual != $expected) {
- $is_continuous = false;
- break;
- }
- $expected++;
- }
-
- if ($is_continuous) {
- $arr = array();
- foreach ($php_val as $k => $v) {
- $arr[$k] = XML_RPC_encode($v);
- }
- $XML_RPC_val->addArray($arr);
- break;
+ $expected = 0;
+ while ((($k = array_shift($keys)) !== NULL) && ($k != $expected++));
+ if ($k === NULL) {
+ $arr = array();
+ foreach ($php_val as $k => $v) {
+ $arr[$k] = XML_RPC_encode($v);
}
+ $XML_RPC_val->addArray($arr);
+ break;
}
// fall though if not numerical and continuous
case "object":