1

I've inherited some code from an ex-colleague and as it has recently been put into production it is causing us some issues. I'm not a php developer so apologies if this appears vague but it has fallen to me (don't ask!).

We are calling a function getLoan() to pre-populate an application form from an existing application. This should return an array, but I am receiving the stdClass error.

$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';

and the function:

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;
}

How can I assign the returned value from the function to $result as an array?

Many thanks

3
  • you say getLoan() is supposed to return an array, yet you are using it as an object right under its call $result->GetResult Commented Sep 27, 2013 at 11:26
  • use type cast like (array)$result Commented Sep 27, 2013 at 11:26
  • Ok in that case do I need to convert it to an object? Commented Sep 27, 2013 at 11:29

1 Answer 1

1
array = json_decode(json_encode(object),true);
Sign up to request clarification or add additional context in comments.

5 Comments

$result = json_decode(json_encode(getLoan(),true)); expects parameter 1 to be string
json_decode() returns array if you pass true as a second parameter. Basically you pass json encoded object to json_decode with true as a second parameter and it will return array of that object. that is how i interchange between array and object
@ajguk you are doing it wrong please check the format of function calls and open and close braces
$result = json_decode(json_decode(getLoan()),true); - same error
My apologies. I am now getting "Trying to get property of non-object" - for $result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.