[phpxmlrpc] Problem with PHP Client/Server -> passing and returning an array

Martin Walter martin.walter at erol.at
Tue Feb 18 17:20:11 GMT 2003


Hello,
 
I am fairly new to the XML-RPC and ran into my first problem. At the
moment I am just testing some custom functions. One of my functions
receives and returns an array. When it run the script i get the
following error:
 
<b>Warning</b>:  htmlspecialchars() expects parameter 1 to be string,
array given in <b>/home/duracell/www/xmlrpc/includes/xmlrpc.inc</b> on
line <b>1204</b>
 
You could see the error on http://www.martinwalter.at/xmlrpc/array.php.
I am using xmlrpc-1.0.99.2 on Apache and PHP 4.2.3.
Please see my code below:
 
Client:
<?php
include('includes/xmlrpc.inc');
 
$client = new xmlrpc_client('/xmlrpc/server.php', 'www.martinwalter.at',
80);
$client -> setDebug(1);
 
$message = new xmlrpcmsg('examples.returnArray', array(new
xmlrpcval(array(new xmlrpcval(1, $xmlrpcInt), new xmlrpcval(2,
$xmlrpcInt), new xmlrpcval(3, $xmlrpcInt)), $xmlrpcArray)));
$result = $client -> send($message);
?>
 
Server:
<?php
include('includes/xmlrpc.inc');
include('includes/xmlrpcs.inc');
 
$errorCounter = 0;
$errorMessage = '';
 
$returnArray_sig = array(array($xmlrpcArray, $xmlrpcArray));
$returnArray_doc = 'Passes a given Array to the client.';
 
function returnArray($xmlrpcMessage)
{
            global $xmlrpcerruser;
            global $errorCounter, $errorMessage;
            
            $returnMessage = $xmlrpcMessage -> getParam(0);
            
            if ($returnMessage -> kindOf() != 'array')
            {
                        $errorMessage = 'Wrong argument type detected.
Required: Array';
                        $errorCounter++;
            }
            
            if ($errorCounter > 0)
            {
                        $response = new xmlrpcresp(0, $xmlrpcerruser,
$errorMessage);
            }
            else
            {
                        $elements = array();
                        
                        for ($i = 0; $i < $returnMessage -> arraysize();
$i++)
                        {
                                   $member = $returnMessage ->
arraymem($i);
                                   $value = $member -> scalarval();
                        
                                   $elements[] = new xmlrpcval($value,
$xmlrpcInt);
                        }
                        
                        $response = new xmlrpcresp(new
xmlrpcval($elements, $xmlrpcArray));
            }
            
            return $response;
}
 
$returnString_sig = array(array($xmlrpcString, $xmlrpcString));
$returnString_doc = 'Passes a given String to the client.';
 
$dispatchMap = array('examples.returnArray' => array('function' =>
'returnArray', 'signature' => $returnArray_sig, 'docstring' =>
$returnArray_doc));
$server = new xmlrpc_server($dispatchMap);
?>
 
I hope you have an idea how to get this fixed? Thanks in advance!
 
Best regards,
Martin Walter
 
mailto: martin.walter at erol.at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20030218/37ec248e/attachment.htm


More information about the phpxmlrpc mailing list