PHP:可捕获的致命错误:类stdClass的对象无法转换为字符串

时间:2011-02-17 17:58:05

标签: php stdclass

我得到以下转储&运行附加代码时出错。令我困惑的是,$ procID似乎是作为字符串返回的,但是一旦我再次尝试传递它,它就是一个对象?我如何让它成为/保持一个字符串?感谢。

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

1 个答案:

答案 0 :(得分: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);