PHP:Errore fatale catchable:Impossibile convertire l'oggetto della classe stdClass in string [closed]

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

  •  14-11-2019
  •  | 
  •  

Domanda

Ottengo il seguente dump e errore durante l'esecuzione del codice allegato.Quello che mi confonde è che proc procID sembra essere restituito come una stringa, ma non appena tento di passarlo di nuovo, è un oggetto?Come faccio ad essere / rimanere una stringa?Grazie.

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));
?>
È stato utile?

Soluzione

Qualunque sia il $client->start() il metodo sta tornando, viene digitato come oggetto.È possibile accedere alle proprietà dell'oggetto utilizzando -> operatore:

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

...

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

Questo era probabilmente un array, ma viene digitato in un oggetto.Così, si finisce con il Classe STD.

Un altro (e forse migliore) modo per farlo è digitare il ritorno.In questo modo, non è necessario creare un nuovo array per passare successivamente come argomento:

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

...

$exchange = $client->exchangeOptions($procID);
$end = $client->stop($procID);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top