[phpxmlrpc] variable number of parameters in client app

Gaetano Giunta giunta.gaetano at gmail.com
Wed Aug 8 10:06:40 BST 2007

Off the top of my head, there are two ways to achieve this:

1 - instead of having an unbounded list of parameters, just use an array as
second parameter, and put the strings inside the array.

Note that in this case the lib will only check that the 2nd param received
is an array, it will not check that the array members are strings, which
might pose a bit of a problem if the api is public (but if a controlled app
is the only client, then your code will mostly be fine without adding
further type checking)

Note 2: you can even have multiple sigs for a single method, this way:

$getObjectById_sig =3D array( array( $xmlrpcStruct, $xmlrpcInt, $xmlrpcStri=
), array( $xmlrpcStruct, $xmlrpcInt, $xmlrpcArray ) );
$getObjectById_doc =3D 'Returns the Object for a given ObjectID and
function getObjectById($m)
   global $xmlrpcerruser;
   $err =3D "";
   $n =3D php_xmlrpc_decode($m);
   $objectID     =3D $n[0];
   $objectTypes =3D $n[1];
   if (is_string($objectTypes))
      $objectTypes =3D array($objectTypes);
   foreach ($objectTypes as $obj)
      // ...

2 - if you remove the method signature from the php array that is fed to the
server object, the lib will not do any check at all on the input parameters
received, but feed directly the request obj tho your php method. This is
closer to a true varargs implementation, but then you should check in code
that you at least got two parameters, the fiurst one being int and all the
others being string (again, if the only caller app is under your control you
might skip those checks)


On 8/8/07, Matthias Korn <korn at prometa.de> wrote:
> Hi,
> i have just a quick question on how to access a variable number of
> parameters in my php client app.
> The current (w/o variable number of parameters) signature and parameter
> access looks like this:
> //-------------------------
> $getObjectById_sig =3D array( array( $xmlrpcStruct, $xmlrpcInt,
> $xmlrpcString ) );
> $getObjectById_doc =3D 'Returns the Object for a given ObjectID and
> itemType.';
> function getObjectById($m)
> {
>     global $xmlrpcerruser;
>     $err =3D "";
>     $n =3D php_xmlrpc_decode($m);
>     $objectID     =3D $n[0];
>     $objectType =3D $n[1];
>     // ...
> //-------------------------
> But now the last param $xmlrpcString (later in $objectType) becomes an
> unknown number of params of the same type (string). The method call I
> get looks like this, where the last parameters is an unknown amount
> (here: three).
> //-------------------------
> <?xml version=3D" 1.0"?>
> <methodCall>
>   <methodName>getObjectById</methodName>
>   <params>
>     <param>
>       <value>
>         <i4>216205</i4>
>       </value>
>     </param>
>     <param>
>       <value>
>         <string>ToDo_ToDo</string>
>       </value>
>     </param>
>     <param>
>       <value>
>         <string>ToDo_Support</string>
>       </value>
>     </param>
>     <param>
>       <value>
>         <string>ToDo_Contact</string>
>       </value>
>     </param>
>   </params>
> </methodCall>
> //-------------------------
> How do I have to modify signature and parameter access to achieve a
> variable number of parameters?
> Thanks a lot,
> Matthias Korn
> _______________________________________________
> phpxmlrpc mailing list
> phpxmlrpc at lists.usefulinc.com
> http://lists.usefulinc.com/cgi-bin/mailman/listinfo/phpxmlrpc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.usefulinc.com/pipermail/phpxmlrpc/attachments/20070808/c8=

More information about the phpxmlrpc mailing list