PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Web Services » XML_RPC » Bug #7381

can not access a method within a class

Details

Submitted2006-04-12 17:08 UTC
Fromstephane at cyberlogic dot ca
Assigneddanielc
StatusClosed
PackageXML_RPC
PHP Version4.4.2
OSLinux
Roadmaps(Not assigned)

Comments

[2006-04-12 17:08 UTC] stephane at cyberlogic dot ca

Description:
------------
XML_RPC 1.4.7

I try to access a method within a class by XML_RPC as shown on the example from the documentation but I get a response "Unknown method" from the server

Test script:
---------------
Server Side :
<?php
require_once 'XML/RPC/Server.php';

class some_class_name {
function returnTimes2($params) {
$param = $params->getParam(0);

// This error checking syntax was added in Release 1.3.0
if (!XML_RPC_Value::isValue($param)) {
return $param;
}

$val = new XML_RPC_Value($param->scalarval() * 3, 'int');
return new XML_RPC_Response($val);
}
}

$some_object = new some_class_name;

// Here are examples of the various ways to declare "functions":
$server = new XML_RPC_Server(

array('class_times2' =>array('function' => array('some_class_name' => 'returnTimes2'),),),
array('class_times3' =>array('function' => 'some_class_name::returnTimes2'),)

);
?>

Client Side :
<?php
require_once 'XML/RPC.php';

$input = 8;

$params = array(new XML_RPC_Value($input, 'int'));

//$msg = new XML_RPC_Message('class_times2', $params);
$msg = new XML_RPC_Message('class_times3', $params);

$cli = new XML_RPC_Client('/webServices/testServer.php', 'localhost');

$cli->setDebug(1);

$resp = $cli->send($msg);

if (!$resp) {
echo 'Communication error: ' . $cli->errstr;
exit;
}

if (!$resp->faultCode()) {
$val = $resp->value();
echo $input . ' times 2 is ' . $val->scalarval();
} else {
/*
* Display problems that have been gracefully cought and
* reported by the xmlrpc.php script.
*/
echo 'Fault Code: ' . $resp->faultCode() . "\n";
echo 'Fault Reason: ' . $resp->faultString() . "\n";
}
?>

Expected result:
----------------
---GOT---
HTTP/1.1 200 OK
Date: Wed, 12 Apr 2006 17:06:06 GMT
Server: Apache
X-Powered-By: PHP/4.4.2-gentoo
Content-Length: 515
Connection: close
Content-Type: text/xml; charset=UTF-8

<?xml version="1.0" encoding="UTF-8"?>
<!-- PEAR XML_RPC SERVER DEBUG INFO:

0 - class xml_rpc_value {
var $me =
array (
'int' => '8',
);
var $mytype = 1;
}

vvv POST DATA RECEIVED BY SERVER vvv
<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>class_times2</methodName>
<params>
<param>
<value><int>8</int></value>
</param>
</params>
</methodCall>

^^^ END POST DATA ^^^
-->
<methodResponse>
<params>
<param>
<value><int>16</int></value>
</param>
</params>
</methodResponse>
---END---

---PARSED---
object(xml_rpc_value)(2) {
["me"]=>
array(1) {
["int"]=>
string(2) "16"
}
["mytype"]=>
int(1)
}
---END---

8 times 2 is 16

Actual result:
--------------
---GOT---
HTTP/1.1 200 OK
Date: Wed, 12 Apr 2006 17:04:33 GMT
Server: Apache
X-Powered-By: PHP/4.4.2-gentoo
Content-Length: 729
Connection: close
Content-Type: text/xml; charset=UTF-8

<?xml version="1.0" encoding="UTF-8"?>
<!-- PEAR XML_RPC SERVER DEBUG INFO:

0 - class xml_rpc_value {
var $me =
array (
'int' => '8',
);
var $mytype = 1;
}

vvv POST DATA RECEIVED BY SERVER vvv
<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>class_times3</methodName>
<params>
<param>
<value><int>8</int></value>
</param>
</params>
</methodCall>

^^^ END POST DATA ^^^
-->
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value><int>1</int></value>
</member>
<member>
<name>faultString</name>
<value><string>Unknown method</string></value>
</member>
</struct>
</value>
</fault>
</methodResponse>
---END---

---PARSED---
object(xml_rpc_value)(2) {
["me"]=>
array(1) {
["struct"]=>
array(2) {
["faultCode"]=>
object(xml_rpc_value)(2) {
["me"]=>
array(1) {
["int"]=>
string(1) "1"
}
["mytype"]=>
int(1)
}
["faultString"]=>
object(xml_rpc_value)(2) {
["me"]=>
array(1) {
["string"]=>
string(14) "Unknown method"
}
["mytype"]=>
int(1)
}
}
}
["mytype"]=>
int(3)
}
---END---

Fault Code: 1 Fault Reason: Unknown method

[2006-04-12 17:14 UTC] stephane at cyberlogic dot ca

Sorry : wrong package ...

[2006-04-12 17:17 UTC] stephane at cyberlogic dot ca

Add Package Version

[2006-04-12 19:29 UTC] stephane at cyberlogic dot ca

ok, I got it ... Sorry

The doc fooled me :
to declare several functions when you create a new instance of XML_RPC_Server, the first argument is an array of array and not ... several arrays !

By the way, I think there is another error on the server side example : in the class some_class_name, the function returnTimes2 doesnot have the word "function" ...

Sorry for the noise