2011-02-17 112 views
2

運行附加代碼時,出現以下轉儲&錯誤。我感到困惑的是,$ procID似乎是以字符串的形式返回的,但只要我嘗試再次傳遞它,它的一個對象?我如何得到它/保持一個字符串?謝謝。PHP:可捕捉的致命錯誤:類stdClass的對象無法轉換爲字符串

 
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)); 
?> 
+2

您確實需要更好地設置您的代碼格式,因此人們不必努力去理解它在做什麼。 – KOGI 2011-02-17 18:00:38

回答

3

無論$client->start()方法返回,它的類型爲一個對象。您可以使用->運營商訪問對象的屬性:

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

... 

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

這可能是一個數組,但得到輸入到一個對象。因此,你最終得到stdClass

另一種(也可能更好)的方法是輸入返回值。這樣,您不必爲以後傳遞的新數組作爲參數:

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

... 

$exchange = $client->exchangeOptions($procID); 
$end = $client->stop($procID); 
+0

謝謝。這工作了一下,現在我碰到了:致命錯誤:Uncaught SoapFault異常:[HTTP]錯誤獲取C:\ wamp \ www \ SugarCE \ testSOAPShawn.php中的http標頭:29堆棧跟蹤:#0 [內部函數]: SoapClient - > __ doRequest('<?xml version =「...','http://10.50.10 ...','',1,0)#1 [內部函數]:SoapClient - > __ call(' C:\ wamp \ www \ SugarCE \ testSOAPShawn.php(29):SoapClient-> establishIdentity(Array)#3 {main}拋出C:\ wamp \ www \ SugarCE \ testSOAPShawn在線29上的.php – user464180 2011-02-17 19:00:45

相關問題