我从前同事那里继承了一些代码,因为它最近投入生产,这给我们带来了一些问题。我不是一个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?
非常感谢
答案 0 :(得分:1)
array = json_decode(json_encode(object),true);