Page 1 of 1

Object of class stdClass could not be converted to string

Posted: Fri Aug 14, 2009 1:58 am
by DjavidJ
Dear all,

Im very new in PHP development and trying to consume a ASP.NET webservice.
This is my code:

Code: Select all

 
<HTML>
<HEAD>
<TITLE>New Document</TITLE>
</HEAD>
<BODY>
<?php
require_once('lib/nusoap.php');
 
$soap = new SoapClient('https://testsoap.test.nl:446/Service1.asmx?wsdl');
try {
$result = $soap->testPhp();
echo "$result";
} catch (SoapFault $e) {
echo "Error: {$e->faultstring}";
}
 
?>
</BODY></HTML>
 
When running this, im getting this error:

PHP Catchable fatal error: Object of class stdClass could not be converted to string . on line 14.

And this is line 14 in my code:
echo "$result";

Can anyone help me with this issue?

Thanks

Re: Object of class stdClass could not be converted to string

Posted: Fri Aug 14, 2009 2:11 am
by requinix
"$result" means to convert $result to a string. Actually, so does trying to echo it. But as I'm sure you figured out, $result cannot be converted to a string. So you need something else to display it.

Since it looks like you're just testing things out and not actually trying to print something specific, use a function like var_dump or print_r instead of echo.

Re: Object of class stdClass could not be converted to string

Posted: Fri Aug 14, 2009 3:02 am
by DjavidJ
Thanks for response tasairis, this issue is solved im can see the response from the server now :)
However i have one more question, i have also a another methode/function in my webservice that asks for some parameters.
im trying to call this with this code:
$perid = '2';
$proid = '2';
$user = 'wq';
$pw = 'er';
$result = $soap->CardWithPerson($perid, $proid, $user, $pw);
var_dump($result);

Bud im getting only the datetime back from the server. it seems that the parameter string wil not pass to the webservice methode. In asp.net it works fine, what is the problem here? (sorry for my english)

Re: Object of class stdClass could not be converted to string

Posted: Fri Aug 14, 2009 3:22 am
by requinix
What do code depends on what kind of structure you need to pass to the service. It could be separate variables, or it could be an array, or it could be an object. Try all three.

Code: Select all

// included for completeness
$result = $soap->CardWithPerson($perid, $proid, $user, $pw);
 
// an array, aka list
$data = array($perid, $proid, $user, $pw);
$result = $soap->CardWithPerson($data);
 
// an associative array, aka hash
$data = array("variable name" => $perid, "other variable name" => $proid, "another variable name" => $user, "last variable name" => $pw);
$result = $soap->CardWithPerson($data);
 
// an associative array that's converted to an object
$data = array("variable name" => $perid, "other variable name" => $proid, "another variable name" => $user, "last variable name" => $pw);
$result = $soap->CardWithPerson((object)$data);
// (object)$data will be an object with ->"variable name" = $perid, etc