XML RPC Web Service

I am looking for a simple xmlrpc webservice code.

I tried kd_xmlrpc_news tutorial code but i keep getting a fatal error cannot reassign $this bla bla bla.

Im actually looking for one that i can post to as well…im looking to remotely post strings and numbers from an iphone.

Any ideas? Suggestions?

The fatal error means something - if you read it properly it will tell you what’s going wrong.

If you post the code and the error, we can probably help you along with that.

here is the function with the error:

function XMLRPC_error($faultCode, $faultString, $server = NULL){
$array[“methodResponse”][“fault”][“value”][“struct”][“member”] = array();
$this = &$array[“methodResponse”][“fault”][“value”][“struct”][“member”];
$this[0][“name”] = “faultCode”;
$this[0][“value”][“int”] = $faultCode;
$this[1][“name”] = “faultString”;
$this[1][“value”][“string”] = $faultString;

$return = XML_serialize($array);

header("Connection: close");
header("Content-Length: " . strlen($return));
header("Content-Type: text/xml");
header("Date: " . date("r"));
if($server){
	header("Server: $server");
}
if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){
	XMLRPC_debug('XMLRPC_error', "<p>Sent the following error response:</p>\


" . XMLRPC_show($return, print_r, true));
}
echo $return;
}

Its in the first few lines where $this is called, the error reads:

Fatal error: Cannot re-assign $this in C:\xampp\htdocs\kd_xmlrpc\kd_xmlrpc.php on line 453

Rename $this to another variable name and it should work.

$this is a reserved variable because it is used within object to access their members, and cannot be used as a normal variable name, even outside of classes/objects.

So try something like this (pun not intended):

function XMLRPC_error($faultCode, $faultString, $server = NULL){
    $array["methodResponse"]["fault"]["value"]["struct"]["member"] = array();
    $member = &$array["methodResponse"]["fault"]["value"]["struct"]["member"];
    $member[0]["name"] = "faultCode";
    $member[0]["value"]["int"] = $faultCode;
    $member[1]["name"] = "faultString";
    $member[1]["value"]["string"] = $faultString;
    $return = XML_serialize($array);
    header("Connection: close");
    header("Content-Length: " . strlen($return));
    header("Content-Type: text/xml");
    header("Date: " . date("r"));
    if($server){
        header("Server: $server");
    }
    if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){
         XMLRPC_debug('XMLRPC_error', "<p>Sent the following error response/p>\
\
" . XMLRPC_show($return, print_r, true));
    }
    echo $return;
}

Or, to shorten things a bit:


function XMLRPC_error($faultCode, $faultString, $server = NULL){
    $array["methodResponse"]["fault"]["value"]["struct"]["member"] = array(
        array('name' => 'faultCode', 'value' => array('int' => $faultCode)),
        array('name' => 'faultString', 'value' => array('string' => $faultString))  
    );
    $return = XML_serialize($array);
    header("Connection: close");
    header("Content-Length: " . strlen($return));
    header("Content-Type: text/xml");
    header("Date: " . date("r"));
    if($server){
        header("Server: $server");
    }
    if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){
         XMLRPC_debug('XMLRPC_error', "<p>Sent the following error response/p>\
\
" . XMLRPC_show($return, print_r, true));
    }
    echo $return;
}

[ot]Where are my manners? :stuck_out_tongue:

Welcome to the forums! :beer:

:D[/ot]