Discussion:
[phpxmlrpc] return an array
didier.geheniau
2008-12-04 23:27:46 UTC
Permalink
Hi all,


I have the following simple code:

<?
include ("lib/xmlrpc.inc");
include ("lib/xmlrpcs.inc");
include ("lib/xmlrpc_wrappers.inc");

$userInfo = new xmlrpcval ( array(
"dgeheniau", new xmlrpcval (
array(
"lastname", new xmlrpcval ("Geheniau",
"string"),
"firstname", new xmlrpcval ("Didier",
"string"),
"email", new xmlrpcval ("email at address.com",
"string")
),
"struct")
), "struct");

$getUserInfo_sig = array(array($xmlrpcStruct, $xmlrpcString));
$getUserInfo_doc = "This function will return all know user info!";

function getUserInfo ($userName){
global $userInfo;
return new xmlrpcresp(new
xmlrpcval($userInfo->structmem("$userName"), "struct"));

}

#$o=new xmlrpc_server_methods_container;
$a=array(
"user.getUserInfo" => array(
"function" => "getUserInfo",
"signature" => $getUserInfo_sig,
"docstring" => $getUserInfo_doc
)
);

$s=new xmlrpc_server($a, false);
$s->setdebug(3);
$s->compress_response = true;
$s->service();
?>

In the client I get:

+++PROCESSING ERRORS AND WARNINGS+++
Object of class xmlrpcmsg could not be converted to string
Undefined index:
+++END+++

What am I doing wrong?

Regards,

Didier
Didier M.J.C. Gehéniau
2008-12-05 12:11:00 UTC
Permalink
Thanks,



That was one problem and de second one i found out: my array was ?lastname?,
?geheniau? and not ?lastname => ?geheniau? ;)



It?s working now







On Fri, Dec 5, 2008 at 12:27 AM, <didier.geheniau at feas.net> wrote:

Hi all,


I have the following simple code:

<?
include ("lib/xmlrpc.inc");
include ("lib/xmlrpcs.inc");
include ("lib/xmlrpc_wrappers.inc");

$userInfo = new xmlrpcval ( array(
"dgeheniau", new xmlrpcval (
array(
"lastname", new xmlrpcval ("Geheniau",
"string"),
"firstname", new xmlrpcval ("Didier",
"string"),
"email", new xmlrpcval ("email at address.com",
"string")
),
"struct")
), "struct");

$getUserInfo_sig = array(array($xmlrpcStruct, $xmlrpcString));
$getUserInfo_doc = "This function will return all know user info!";

function getUserInfo ($userName){


Here $userName will not be a string but an object.
You will need to extract the 1st param received from this object, and its
then its string value.
Btw, if you are doing all the encoding/decoding from php values to xmlrpc
values by hand you do not need to include xmlrpc_wrappers.inc - that lib is
used when you want to automatically turn plain php functions (ie functions
that do not deal with xmlrpcvals) into server methods.

Bye
Gaetano


global $userInfo;
return new xmlrpcresp(new
xmlrpcval($userInfo->structmem("$userName"), "struct"));

}

#$o=new xmlrpc_server_methods_container;
$a=array(
"user.getUserInfo" => array(
"function" => "getUserInfo",
"signature" => $getUserInfo_sig,
"docstring" => $getUserInfo_doc
)
);

$s=new xmlrpc_server($a, false);
$s->setdebug(3);
$s->compress_response = true;
$s->service();
?>

In the client I get:

+++PROCESSING ERRORS AND WARNINGS+++
Object of class xmlrpcmsg could not be converted to string
Undefined index:
+++END+++

What am I doing wrong?

Regards,

Didier



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.usefulinc.com/pipermail/phpxmlrpc/attachments/20081205/8eb19983/attachment.htm
Continue reading on narkive:
Loading...