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 #3571

XML_PRC can't work correctly with statement "foreach (array as $key=>$value)"

Details

Submitted2005-02-24 06:45 UTC
Frombluemonkey157 at hotmail dot com
Assigneddanielc
StatusBogus
PackageXML_RPC
PHP Version4.3.11
OSwin2000
Roadmaps(Not assigned)

Comments

[2005-02-24 06:45 UTC] bluemonkey157 at hotmail dot com

Description:
------------
XML_RPC version: XML_RPC-1.1.0
DB version: DB-1.6.8

pear XML_PRC can't work with Pear DB, but they can work apart, so I think It's a bug.
Finally, I replace all
"foreach (array_expression as $value) statement" to
"foreach (array_expression as $key => $value) statement"
in file DB\common.php, it can work right.

For example:
before modify:
function prepare($query)
{
....
foreach ($tokens as $val) {
switch ($val) {
....
}
}
....
}

after modify:
function prepare($query)
{
....
foreach ($tokens as $key => $val) {
switch ($val) {
....
}
}
....
}

[2005-02-24 09:10 UTC] bluemonkey157 at hotmail dot com

XML_PRC can't work correctly with statement "foreach (array as $key=>$value)".

When I use "foreach (array_expression as $value) statement",It cause an error, "$value" can't get correct value, but I use "foreach (array_expression as $key => $value) statement", It is correct. So I think It's a bug.

For example:
case wrong:
function foreachArray($message)
{
$str = null;
$ar = array("I", "love", "you");
foreach ($ar as $value) {
$str .= $value;
}
$result = new XML_RPC_Value($str, "string");
return new XML_RPC_Response($result);
}

case right:
function foreachArray($message)
{
$str = null;
$ar = array("I", "love", "you");
foreach ($ar as $key => $value) {
$str .= $value;
}
$result = new XML_RPC_Value($str, "string");
return new XML_RPC_Response($result);
}

[2005-02-25 08:21 UTC] bluemonkey157 at hotmail dot com

I test it with php 4.3.11, but the problem still exist.

[2005-02-28 01:38 UTC] bluemonkey157 at hotmail dot com

My Develop environment:
win2000
php 4.3.11
DB 1.6.8
XML_RPC 1.1.0

I run your example, and get the expected response, but my script is still get unexpected response, so I post my script file here:

Client.php
------------------------------------------------------------
<?php

require_once('XML/RPC.php');

$function = "foreachArray";
$message = new XML_RPC_Message($function);
$client = new XML_RPC_Client("/bugs/Server.php", "localhost", 80);
$result = $client->send($message);

echo "<p><b>Function Call:</b> $function()</p>";
echo "<p><b>Sent XML Message:</b>" .
"<pre>" . htmlentities($message->serialize()) . "</pre></p>";
$value = $result->value();
if (!isset($value)) {
die("send failed");
}
$isSuccess = $value->scalarval();
echo "<p><b>Return Value:</b> $isSuccess </p>";
echo "<p><b>Received XML Message:</b>" .
"<pre>" . htmlentities($result->serialize()) . "</pre></p>";

?>
------------------------------------------------------------

Server.php
------------------------------------------------------------
<?php

require_once('XML/RPC/Server.php');
require_once('Handle.php');

$foreachArraySig = array(array("string"));
$foreachArrayArr = array("function" => "foreachArray", "signature" => $foreachArraySig);
$dispMap = array("foreachArray" => $foreachArrayArr);
new XML_RPC_Server($dispMap);

?>
------------------------------------------------------------

Handle.php
------------------------------------------------------------
<?php

function foreachArray($message)
{
$str = null;
$ar = array("How", "do", "you", "do");
//foreach ($ar as $key => $value) {
foreach ($ar as $value) {
$str .= $value;
}
$result = new XML_RPC_Value($str, "string");
return new XML_RPC_Response($result);
}

?>
------------------------------------------------------------

EXPECTED RESPONSE(in browser):
------------------------------------------------------------
Function Call: foreachArray()

Sent XML Message:

<?xml version="1.0"?>
<methodCall>
<methodName>foreachArray</methodName>
<params>
</params>
</methodCall>

Return Value: Howdoyoudo

Received XML Message:

<methodResponse>
<params>
<param>
<value><string>Howdoyoudo</string></value>
</param>
</params>
</methodResponse>
------------------------------------------------------------

but I get response(in browser):
------------------------------------------------------------
Function Call: foreachArray()

Sent XML Message:

<?xml version="1.0"?>
<methodCall>
<methodName>foreachArray</methodName>
<params>
</params>
</methodCall>

Return Value: ArrayArrayArrayArray

Received XML Message:

<methodResponse>
<params>
<param>
<value><string>ArrayArrayArrayArray</string></value>
</param>
</params>
</methodResponse>
------------------------------------------------------------