Re: XML_PRC can't work correctly with statement "foreach (array as $value)"

From: Date: Mon, 28 Feb 2005 06:21:46 +0000
Subject: Re: XML_PRC can't work correctly with statement "foreach (array as $value)"
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-17720@lists.php.net to get a copy of this message
On Mon, 28 Feb 2005 13:54:50 +0800, ylh <bluemonkey157@hotmail.com> wrote: > My Develop environment: > win2000 > php 4.3.11 > DB 1.6.8 > XML_RPC 1.2.0 > > XML_PRC can't work correctly with statement "foreach (array as $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. > > 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 unexpected 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> > ------------------------------------------------------------ > Have you tried that in a normal script? (i.e. not with XML_RPC)? Perhaps you should try with PHP 4.3.10 or 4.3.9 since 4.3.11 *isn't released yet*. Also, this sounds much more like a PHP bug than an XML_RPC bug. -- Justin Patrin

« previous php.pear.general (#17720) next »