By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,855 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

A quick question about xml-rpc

P: n/a
for the following code, why it uses $method = 'examples.getStateName';
instead of $method = 'getStateName'; or $method =
'examples.getStateName()'

What does "example" here mean? Thanks

<?php
// this is the default file name from the package
// kept here to avoid confusion over the file name
require 'utils.php';

// server settings
$host = 'betty.userland.com';
$port = 80;
$uri = '/RPC2';

// request settings
// pass in a number from 1-50; get the nth state in alphabetical order
// 1 is Alabama, 50 is Wyoming
$method = 'examples.getStateName';
$args = array(32); // data to be passed

// make associative array out of these variables
$request = compact('host', 'port', 'uri', 'method', 'args');

// this function makes the XML-RPC request
$result = xu_rpc_http_concise($request);

print "I love $result!\n";
?>

May 10 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On May 10, 4:47 pm, Ming <minghu...@gmail.comwrote:
for the following code, why it uses $method = 'examples.getStateName';
instead of $method = 'getStateName'; or $method =
'examples.getStateName()'

What does "example" here mean? Thanks

$method = 'examples.getStateName';
$args = array(32); // data to be passed
$request = compact('host', 'port', 'uri', 'method', 'args');
$result = xu_rpc_http_concise($request);
It means the getStateName function is a method of the 'examples'
object. You don't need to put parenthesis on the end of the method
because there are never any arguments to put in there. The arguments
in an xml-rpc request go in the 'args' index of the array you pass to
xu_rpc_http_concise(). The whole thing with the compact() call
basically does the same thing as this:

<?php
xu_rpc_http_concise(
array(
'method' ='examples.getStateName',
'args' =array( 32 ),
'host' ='...',
'port' ='...',
'uri' ='...'
)
)
?>

....because xu_rpc_http_concise() takes an associative array of it's
arguments instead of just the arguments in the parenthesis on the
function. What the example would look like if you were calling the
same method if it were right in PHP would be something like:

<?php
$examples = new SomeClass();
$result = $examples->getStateName( 32 );
echo "I love $result!\n";
?>

Where SomeClass is some class that has a getStateName() method that
does whatever the xml-rpc method does.

-Mike PII

May 10 '07 #2

P: n/a
Thanks Mike. I still do not quite understand. I do not have any class
that has getStateName method. It is an object in the remote machine
that has this method, isn't it? Correct me if I am wrong, it sounds it
is sufficient to just send $method = 'getStateName'

Ming

On May 10, 3:42 pm, Mike P2 <sumguyovrt...@gmail.comwrote:
On May 10, 4:47 pm, Ming <minghu...@gmail.comwrote:
for the following code, why it uses $method = 'examples.getStateName';
instead of $method = 'getStateName'; or $method =
'examples.getStateName()'
What does "example" here mean? Thanks
$method = 'examples.getStateName';
$args = array(32); // data to be passed
$request = compact('host', 'port', 'uri', 'method', 'args');
$result = xu_rpc_http_concise($request);

It means the getStateName function is a method of the 'examples'
object. You don't need to put parenthesis on the end of the method
because there are never any arguments to put in there. The arguments
in an xml-rpc request go in the 'args' index of the array you pass to
xu_rpc_http_concise(). The whole thing with the compact() call
basically does the same thing as this:

<?php
xu_rpc_http_concise(
array(
'method' ='examples.getStateName',
'args' =array( 32 ),
'host' ='...',
'port' ='...',
'uri' ='...'
)
)
?>

...because xu_rpc_http_concise() takes an associative array of it's
arguments instead of just the arguments in the parenthesis on the
function. What the example would look like if you were calling the
same method if it were right in PHP would be something like:

<?php
$examples = new SomeClass();
$result = $examples->getStateName( 32 );
echo "I love $result!\n";
?>

Where SomeClass is some class that has a getStateName() method that
does whatever the xml-rpc method does.

-Mike PII

May 10 '07 #3

P: n/a
On May 10, 7:06 pm, Ming <minghu...@gmail.comwrote:
Thanks Mike. I still do not quite understand. I do not have any class
that has getStateName method. It is an object in the remote machine
that has this method, isn't it? Correct me if I am wrong, it sounds it
is sufficient to just send $method = 'getStateName'

Ming
Yes, the object is on the remote machine, and the method
'getStateName' is within that object. Just like you might organize
methods into classes in your own php code, the remote machine has
getStateName() organized into an 'examples' object.

In PHP, if you have an object instance in the variable $examples and
the class that it is an instance of has the method getStateName(), you
can't just do:

$whatever = getStateName();

You have to do

$whatever = $examples->getStateName();

Because getStateName() is not in the global scope, it is in the
$examples object.

If you still don't understand and would like to know why you have to
put in 'examples', maybe you should study PHP OOP more to get a better
understanding of OOP.

-Mike PII

May 10 '07 #4

P: n/a
On May 10, 4:54 pm, Mike P2 <sumguyovrt...@gmail.comwrote:
On May 10, 7:06 pm, Ming <minghu...@gmail.comwrote:
Thanks Mike. I still do not quite understand. I do not have any class
that has getStateName method. It is an object in the remote machine
that has this method, isn't it? Correct me if I am wrong, it sounds it
is sufficient to just send $method = 'getStateName'
Ming

Yes, the object is on the remote machine, and the method
'getStateName' is within that object. Just like you might organize
methods into classes in your own php code, the remote machine has
getStateName() organized into an 'examples' object.

In PHP, if you have an object instance in the variable $examples and
the class that it is an instance of has the method getStateName(), you
can't just do:

$whatever = getStateName();

You have to do

$whatever = $examples->getStateName();

Because getStateName() is not in the global scope, it is in the
$examples object.

If you still don't understand and would like to know why you have to
put in 'examples', maybe you should study PHP OOP more to get a better
understanding of OOP.

-Mike PII

Hi Mike,

Thanks for reply.

I have used OOP and Java for several years so I understand OOP
concepts. Back to my question, it seems the 'examples' in $method =
'examples.getStateName' is arbitrary. Can I change it to other words?

Thanks a lot,

Ming

May 11 '07 #5

P: n/a
On May 10, 9:31 pm, Ming <minghu...@gmail.comwrote:
Hi Mike,

Thanks for reply.

I have used OOP and Java for several years so I understand OOP
concepts. Back to my question, it seems the 'examples' in $method =
'examples.getStateName' is arbitrary. Can I change it to other words?

Thanks a lot,

Ming
Oh, so you're curious because changing it doesn't have any effect...

I have no idea why it acts that way. That's weird.

Sorry,
Mike PII

May 11 '07 #6

P: n/a
..oO(Ming)
>I have used OOP and Java for several years so I understand OOP
concepts. Back to my question, it seems the 'examples' in $method =
'examples.getStateName' is arbitrary. Can I change it to other words?
I would say it entirely depends on what the RPC server expects. If the
server requires a call to be like 'object.method' then you have to use
it that way. But it could also be something completely different. So I
think you need some more informations about what methods are available
on the RPC server and how you have to call them.

Micha
May 11 '07 #7

P: n/a
Ming wrote:
On May 10, 4:54 pm, Mike P2 <sumguyovrt...@gmail.comwrote:
>On May 10, 7:06 pm, Ming <minghu...@gmail.comwrote:
>>Thanks Mike. I still do not quite understand. I do not have any class
that has getStateName method. It is an object in the remote machine
that has this method, isn't it? Correct me if I am wrong, it sounds it
is sufficient to just send $method = 'getStateName'
Ming
Yes, the object is on the remote machine, and the method
'getStateName' is within that object. Just like you might organize
methods into classes in your own php code, the remote machine has
getStateName() organized into an 'examples' object.

In PHP, if you have an object instance in the variable $examples and
the class that it is an instance of has the method getStateName(), you
can't just do:

$whatever = getStateName();

You have to do

$whatever = $examples->getStateName();

Because getStateName() is not in the global scope, it is in the
$examples object.

If you still don't understand and would like to know why you have to
put in 'examples', maybe you should study PHP OOP more to get a better
understanding of OOP.

-Mike PII


Hi Mike,

Thanks for reply.

I have used OOP and Java for several years so I understand OOP
concepts. Back to my question, it seems the 'examples' in $method =
'examples.getStateName' is arbitrary. Can I change it to other words?

Thanks a lot,

Ming
Ming,

It has nothing to do with YOUR code. You're calling a procedure on the
SERVER.

In this case the procedure defined by the server is
example.getStateName. It can be foo.bar, if you change it on both ends.

It's just like a web page. You can create a web page with any (legal)
name you want. But if you want a browser to display the page, the
browser has to use the URI defined at the server.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 11 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.