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

32,262

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);
Share:
32,262

Related videos on Youtube

user464180
Author by

user464180

Updated on July 09, 2022

Comments

  • user464180
    user464180 11 months

    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));
    ?>
    
    • KOGI
      KOGI over 12 years
      You really need to format your code better so people don't have to work as hard to understand what it's doing.
  • user464180
    user464180 over 12 years
    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('<?xml version="...', '10.50.10...', '', 1, 0) #1 [internal function]: SoapClient->__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
  • Chris Baker
    Chris Baker over 12 years
    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.
  • Travis Heeter
    Travis Heeter over 10 years
    @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.

Related