Php 致命错误:无法将stdClass用作数组

Php 致命错误:无法将stdClass用作数组,php,stdclass,Php,Stdclass,我从一位前同事那里继承了一些代码,因为它最近已经投入生产,这给我们带来了一些问题。我不是一个php开发人员,所以如果这看起来很模糊,我深表歉意,但这是我的责任(不要问!) 我们正在调用函数getLoan(),从现有应用程序中预填充申请表。这将返回一个数组,但我收到stdClass错误 $result = getLoan(); //this is the line that is erroring if (isset($result->GetResult->Debtor->Add

我从一位前同事那里继承了一些代码,因为它最近已经投入生产,这给我们带来了一些问题。我不是一个php开发人员,所以如果这看起来很模糊,我深表歉意,但这是我的责任(不要问!)

我们正在调用函数
getLoan()
,从现有应用程序中预填充申请表。这将返回一个数组,但我收到stdClass错误

$result = getLoan(); //this is the line that is erroring
if (isset($result->GetResult->Debtor->Addresses->Address[0])) $current_address = clone     $result->GetResult->Debtor->Addresses->Address[0];
else $current_address = clone $result->GetResult->Debtor->Addresses->Address;

if ($result === false)
{
  echo("No LID given");
  die;
}
$attr = 'selected';
以及功能:

function getLoan() {
//globals
/*
global $client;
global $test;
global $result;
*/
global $thisurl;

if (isset($_GET['LID'])) 
         $pLoanID = $_GET['LID'];
else 
         return false;
$test = array(
        "pLoanID" => $pLoanID,
);

//print_r($Address); //print address object as a test
//send to gateway starts**********
$url = "https://www.blahblah.asmx?WSDL";
$client = new SoapClient($url, array("trace" => 1, "exception" => 0));

try {
    $result = $client->Get($test);
}
catch(Exception $e) {
    //header("Location: http://" . $_SERVER['REMOTE_ADDR'] . "/application-form-new");
    print_r($e);
    exit;
}

$thisurl = "continue-app?LID=" . $pLoanID;
if (isset($result)) return $result;
else return false;
}
如何将函数返回的值作为数组分配给$result


非常感谢

你说
getLoan()
应该返回一个数组,而你却把它作为一个对象使用,就在它的调用下
$result->GetResult
使用类型转换(数组)$resultOk在这种情况下我需要将它转换成一个对象吗?你说
getLoan()
应该返回一个数组,然而,您正在将它作为一个对象使用,就在它的调用下
$result->GetResult
使用类型转换(数组)$resultOk在这种情况下,我需要将它转换为一个对象吗?
$result=json_decode(json_encode(getLoan(),true))
希望参数1为stringjson_decode(),如果将true作为第二个参数传递,则返回数组。基本上,将json编码的对象传递给json_decode,并将true作为第二个参数,它将返回该对象的数组。这就是我如何在数组和object@ajguk您做错了,请检查函数调用的格式,并打开和关闭大括号
$result=json_decode(json_decode(getLoan()),true)-同样的错误我很抱歉。我现在得到了$result
$result=json_decode(json_encode(getLoan(),true))的“尝试获取非对象的属性”
希望参数1为stringjson_decode(),如果将true作为第二个参数传递,则返回数组。基本上,将json编码的对象传递给json_decode,并将true作为第二个参数,它将返回该对象的数组。这就是我如何在数组和object@ajguk您做错了,请检查函数调用的格式,并打开和关闭大括号
$result=json_decode(json_decode(getLoan()),true)-同样的错误我很抱歉。我现在得到了$result的“尝试获取非对象的属性”
array = json_decode(json_encode(object),true);