Re: [qooxdoo-devel] Object Parameter in rpc call problem
Peter,
thank you ... I'm not a php programmer, maybe this explains my question ;-)
Cheers,
Maik
Am 05.06.2012 10:24, schrieb Peter Schneider:
> Hi Connor,
>
> the error says it already ;)
> "Cannot use object of type stdClass as array"
>
> The $params[0] at your PHP server should be accessed via the 'member-operator'
> of PHP ('->'), not the array operator ('[]').
>
> So instead of
> $retval[] = "Client said: " . $params[0]["left"][0];
> you should do something like
> $retval[] = "Client said: " . $params[0]->left[0];
> ...when your JSON (RPC-)Data from the frontend was like this
> {"left":["top","XYZ"]}
>
> A bit more detailed:
>
> /**
>* Echoes the request
>*
>* @param {array} params
>* An array containing the parameters to this method
>*
>* @param {JsonRpcError} error
>* An object of class JsonRpcError.
>*
>* @return
>* Success: The object containing the result of the method;
>* Failure: null
>*/
> function method_echo($params, $error)
> {
> // ...error check removed for clarity...
>
> $req = $params[0]; // {stdClass}
>
> $leftVal = $req->left; // 2-element {array}
>
> $first = $leftVal[0]; // {String}
> $second= $leftVal[1]; // {String}
>
> return $req; // Let's return the complete request parameter set!
> }
>
>
>
>
> General rule:
> JSON | PHP
> --+-
> ["foo","bar"] | $x[0] === "foo"; $x[1] === "bar";
> {key:"val"} | $foo->key === "val"
>
>
> Cheers,
> Peter
>
>
>
> On 6/1/2012 4:57 PM Connor wrote:
>> Hi,
>> I have a problem with passing javascript objects to my PHP RPC Server as a
>> parameter.
>> Does anybody know whats wrong here ?
>>
>> thanks in advance,
>> Connor.
>>
>> With the PHP RPC Server I've adjusted the echo method to:
>>
>> function method_echo($params, $error)
>>
>> {
>>
>> if (count($params) != 1)
>>
>> {
>>
>> $error->SetError(JsonRpcError_ParameterMismatch,
>>
>> "Expected 1 parameter; got " . count($params));
>>
>> return $error;
>>
>> }
>>
>>
>>
>> $retval[] = "Test";
>>
>> $retval[] = "Client said: " . $params[0]["left"][0];
>>
>> return $retval;
>>
>> }
>>
>>
>> and passed the parameter by the qooxdoo application like
>>
>>try {
>>
>> var result = rpc.callSync("echo", {"left":["top","XYZ"]});
>>
>> alert("Result of sync call: " + result);
>>
>>} catch (exc) {
>>
>> alert("Exception during sync call: " + exc);
>>
>>}
>>
>>
>> This causes an error message in php:
>>
>> /*
>> ( ! ) Fatal error: Cannot use object of type stdClass as array in
>> C:\XAMPP\xampp\htdocs\rpc\qooxdoo\services\class\tmlproxy\tml.php on line
>> /59/
>> Call Stack
>> #TimeMemory FunctionLocation
>> 10.0007 336568 {main}( ) ..\index.php*:*0
>> 20.0091 772536 JsonRpcServer::run( ) ..\index.php*:*34
>> 30.0121 780008 JsonRpcServer->start( )
>> ..\JsonRpcServer.php*:*141
>> 40.0121 780848 AbstractServer->start( )
>> ..\JsonRpcServer.php*:*165
>> 50.0409 1044480 JsonRpcServer->callServiceMethod( )
>> ..\AbstractServer.php*:*599
>> 60.0410 1044480 AbstractServer->callServiceMethod( )
>> ..\JsonRpcServer.php*:*347
>> 70.0410 1045944 class_tml->method_echo( )
>> ..\AbstractServer.php*:*941
>>
>> */{ error: { "origin":1, "code":-1, "message":"Fatal PHP Error. See response
>> content for error description "}}
>>
>> The Post seems to be correct:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> POST index.php?nocache=1338562470553
>>
>> 200 OK
>>
>> localhost:8080
>>
>> 3.1 KB
>>
>> ::1:8080
>>
>>
>> 51ms
>> ParameterHeaderPostAntwortHTML
>> JSON
>>
>>
>>
>>
>>
>> id
>> 9
>>
>>
>> method
>> "echo"
>>
>>
>> params
>> [Object { left=[2]}]
>>
>>
>> service
>> "tmlproxy.tml"
>>
>> Quelle
>> |{"service":"tmlproxy.tml","method":"echo","id":9,"params":[{"left":["top","XYZ"]}]}|
>>
>>
>>
>> 1 Anfrage
>>
>>
>>
>> 3.1 KB
>>
>> 51ms
>
> Besuchen Sie uns: 12.-14. Juni 2012, transfairlog Hamburg Halle A3,
> Stand 410
--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Re: [qooxdoo-devel] Object Parameter in rpc call problem
Hi Connor,
the error says it already ;)
"Cannot use object of type stdClass as array"
The $params[0] at your PHP server should be accessed via the 'member-operator'
of PHP ('->'), not the array operator ('[]').
So instead of
$retval[] = "Client said: " . $params[0]["left"][0];
you should do something like
$retval[] = "Client said: " . $params[0]->left[0];
...when your JSON (RPC-)Data from the frontend was like this
{"left":["top","XYZ"]}
A bit more detailed:
/**
* Echoes the request
*
* @param {array} params
* An array containing the parameters to this method
*
* @param {JsonRpcError} error
* An object of class JsonRpcError.
*
* @return
* Success: The object containing the result of the method;
* Failure: null
*/
function method_echo($params, $error)
{
// ...error check removed for clarity...
$req = $params[0]; // {stdClass}
$leftVal = $req->left; // 2-element {array}
$first = $leftVal[0]; // {String}
$second= $leftVal[1]; // {String}
return $req; // Let's return the complete request parameter set!
}
General rule:
JSON | PHP
--+-
["foo","bar"] | $x[0] === "foo"; $x[1] === "bar";
{key:"val"} | $foo->key === "val"
Cheers,
Peter
On 6/1/2012 4:57 PM Connor wrote:
> Hi,
> I have a problem with passing javascript objects to my PHP RPC Server as a
> parameter.
> Does anybody know whats wrong here ?
>
> thanks in advance,
> Connor.
>
> With the PHP RPC Server I've adjusted the echo method to:
>
> function method_echo($params, $error)
>
> {
>
> if (count($params) != 1)
>
> {
>
> $error->SetError(JsonRpcError_ParameterMismatch,
>
> "Expected 1 parameter; got " . count($params));
>
> return $error;
>
> }
>
>
>
> $retval[] = "Test";
>
> $retval[] = "Client said: " . $params[0]["left"][0];
>
> return $retval;
>
> }
>
>
> and passed the parameter by the qooxdoo application like
>
>try {
>
> var result = rpc.callSync("echo", {"left":["top","XYZ"]});
>
> alert("Result of sync call: " + result);
>
>} catch (exc) {
>
> alert("Exception during sync call: " + exc);
>
>}
>
>
> This causes an error message in php:
>
> /*
> ( ! ) Fatal error: Cannot use object of type stdClass as array in
> C:\XAMPP\xampp\htdocs\rpc\qooxdoo\services\class\tmlproxy\tml.php on line /59/
> Call Stack
> # TimeMemory FunctionLocation
> 1 0.0007 336568 {main}( ) ..\index.php*:*0
> 2 0.0091 772536 JsonRpcServer::run( ) ..\index.php*:*34
> 3 0.0121 780008 JsonRpcServer->start( )
> ..\JsonRpcServer.php*:*141
> 4 0.0121 780848 AbstractServer->start( )
> ..\JsonRpcServer.php*:*165
> 5 0.0409 1044480 JsonRpcServer->callServiceMethod( )
> ..\AbstractServer.php*:*599
> 6 0.0410 1044480 AbstractServer->callServiceMethod( )
> ..\JsonRpcServer.php*:*347
> 7 0.0410 1045944 class_tml->method_echo( )
> ..\AbstractServer.php*:*941
>
> */{ error: { "origin":1, "code":-1, "message":"Fatal PHP Error. See response
> content for error description "}}
>
> The Post seems to be correct:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> POST index.php?nocache=1338562470553
>
> 200 OK
>
> localhost:8080
>
> 3.1 KB
>
> ::1:8080
>
>
> 51ms
> ParameterHeaderPostAntwortHTML
> JSON
>
>
>
>
>
> id
> 9
>
>
> method
> "echo"
>
>
> params
> [Object { left=[2]}]
>
>
> service
> "tmlproxy.tml"
>
> Quelle
> |{"service":"tmlproxy.tml","method":"echo","id":9,"params":[{"left":["top","XYZ"]}]}|
>
>
>
> 1 Anfrage
>
>
>
> 3.1 KB
>
> 51ms
Besuchen Sie uns: 12.-14. Juni 2012, transfairlog Hamburg Halle A3, Stand
410
--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
[qooxdoo-devel] Object Parameter in rpc call problem
Hi,
I have a problem with passing javascript objects to my PHP RPC Server as
a parameter.
Does anybody know whats wrong here ?
thanks in advance,
Connor.
With the PHP RPC Server I've adjusted the echo method to:
function method_echo($params, $error)
{
if (count($params) != 1)
{
$error->SetError(JsonRpcError_ParameterMismatch,
"Expected 1 parameter; got " . count($params));
return $error;
}
$retval[] = "Test";
$retval[] = "Client said: " . $params[0]["left"][0];
return $retval;
}
and passed the parameter by the qooxdoo application like
try {
var result = rpc.callSync("echo", {"left":["top","XYZ"]});
alert("Result of sync call: " + result);
} catch (exc) {
alert("Exception during sync call: " + exc);
}
This causes an error message in php:
/*
( ! ) Fatal error: Cannot use object of type stdClass as array in
C:\XAMPP\xampp\htdocs\rpc\qooxdoo\services\class\tmlproxy\tml.php on
line /59/
Call Stack
# TimeMemory FunctionLocation
1 0.0007 336568 {main}( ) ..\index.php*:*0
2 0.0091 772536 JsonRpcServer::run( ) ..\index.php*:*34
3 0.0121 780008 JsonRpcServer->start( )
..\JsonRpcServer.php*:*141
4 0.0121 780848 AbstractServer->start( )
..\JsonRpcServer.php*:*165
5 0.0409 1044480 JsonRpcServer->callServiceMethod( )
..\AbstractServer.php*:*599
6 0.0410 1044480 AbstractServer->callServiceMethod( )
..\JsonRpcServer.php*:*347
7 0.0410 1045944 class_tml->method_echo( )
..\AbstractServer.php*:*941
*/{ error: { "origin":1, "code":-1, "message":"Fatal PHP Error. See
response content for error description "}}
The Post seems to be correct:
POST index.php?nocache=1338562470553
200 OK
localhost:8080
3.1 KB
::1:8080
51ms
ParameterHeaderPostAntwortHTML
JSON
id
9
method
"echo"
params
[Object { left=[2]}]
service
"tmlproxy.tml"
Quelle
|{"service":"tmlproxy.tml","method":"echo","id":9,"params":[{"left":["top","XYZ"]}]}|
1 Anfrage
3.1 KB
51ms
--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
