PHP:可捕获的致命错误:类stdClass的对象无法转换为字符串 [英] PHP: Catchable fatal error: Object of class stdClass could not be converted to string
问题描述
我得到以下转储&运行附加代码时发生错误.我感到困惑的是,$ procID似乎以字符串形式返回,但是一旦我尝试再次传递它,它就是一个对象?我如何获得它作为/保持字符串?谢谢.
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));
?>
推荐答案
无论$client->start()
方法返回什么,都将其键入为对象.您可以使用->
运算符访问对象的属性:
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));
这可能是一个数组,但是正在输入一个对象.因此,您最终得到了 stdClass .
This was probably an array, but is getting typed into an object. Thus, you end up with the stdClass.
另一种(可能更好)的方法是键入return.这样,您就不必为稍后作为参数传递而创建新的数组:
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);
这篇关于PHP:可捕获的致命错误:类stdClass的对象无法转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!