PHP: Catchable fatal error: Object of class stdClass could not be converted to string [closed]

StackOverflow https://stackoverflow.com/questions/5032687

  •  14-11-2019
  •  | 
  •  

Question

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));
?>
Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top