2

I get the following dump & error when running the attached code. What I'm confused by is that $procID appears to be returned as a string, but as soon as I attempt to pass it again, its an object? How do I get it to be/stay a string? Thanks.

object(stdClass)#2 (1) {
["processId"]=> string(13)
"Genesis114001" }  string(311)
"Genesis114001" string(293) " Genesis
" Catchable fatal error: Object of
class stdClass could not be converted
to string in
C:\wamp\www\SugarCE\testSOAPShawn.php
on line 15
<?php
set_time_limit(0);
require_once('nusoap.php');
require_once('BenefitSOAP.php');  //WSDL to PHP Classes
$client = new SoapClient('C:\wsdl\BenefitDeterminationProcess_BenefitDialogueServiceSOAP.wsdl', array('trace' => 1));
$procID = $client->start(array("prefix"=>"Genesis"));
$respXML = $client->__getLastResponse();
$requXML = $client->__getLastRequest();
echo "<p/>";
var_dump($procID);
//echo "<p/>";
var_dump($respXML);
//echo "<p/>";
var_dump($requXML);
$exchange = $client->exchangeOptions(array("processId"=>$procID)); //LINE 15
$end = $client->stop(array("processId"=>$procID));
?>
ajreal
  • 46,720
  • 11
  • 89
  • 119
user464180
  • 1,349
  • 2
  • 23
  • 46
  • 2
    You really need to format your code better so people don't have to work as hard to understand what it's doing. – KOGI Feb 17 '11 at 18:00

1 Answers1

3

Whatever the $client->start() method is returning, it is typed as an object. You can access the properties of the object using the -> operator:

$procID = $client->start(array("prefix"=>"Genesis"));

...

$exchange = $client->exchangeOptions(array("processId"=>$procID->processId));

This was probably an array, but is getting typed into an object. Thus, you end up with the stdClass.

Another (and possibly better) way to do this is to type the return. That way, you don't have to make a new array for later passing as argument:

$procID = (array) $client->start(array("prefix"=>"Genesis"));

...

$exchange = $client->exchangeOptions($procID);
$end = $client->stop($procID);
Chris Baker
  • 49,926
  • 12
  • 96
  • 115
  • Thanks. That worked a bit, now I get hit with:Fatal error: Uncaught SoapFault exception: [HTTP] Error Fetching http headers in C:\wamp\www\SugarCE\testSOAPShawn.php:29 Stack trace: #0 [internal function]: SoapClient->__doRequest('__call('establishIdenti...', Array) #2 C:\wamp\www\SugarCE\testSOAPShawn.php(29): SoapClient->establishIdentity(Array) #3 {main} thrown in C:\wamp\www\SugarCE\testSOAPShawn.php on line 29 – user464180 Feb 17 '11 at 19:00
  • That error is completely unrelated to this question. There's an issue somewhere either in the library you are using, or the way you are using it. Without knowing either of those facts, I can't really advise you either way. I would suggest starting a new question regarding this - but be sure to accept an answer here. – Chris Baker Feb 17 '11 at 19:19
  • @Chris Thanks for this, you explanation makes sense, but I'm having an issue with your solution. I've tried both ways and I still get stdClass could not be converted to a string. Here's what I got: `$res_array = (array) $php_functions->run_query('SHOW TABLES'); echo implode(',', $res_array);` run_query produces an array of the query results. – Travis Heeter Oct 27 '12 at 15:34