0

Need some help please. I am getting a 'Trying to get property of non-object' error in a function call that looks at an array.

The array I am calling is

$var = array(
    "variableA" => "abc123",
    "variableB" => "123456789"
);

The function I am using is

  public function getJson($var)
    {
 $resource = sprintf("/info/%s/%s/json", $var->variableA, $var->variableB);
        return $this->_restCall('GET', $resource);
     }

I cant understand why the array values are not being passed through?

Could someone please help?

1 Answer 1

4

$var is an array not an object. So you need to use array syntax, not object syntax:

public function getJson($var)
{
    $resource = sprintf("/info/%s/%s/json", $var['variableA'], $var['variableB']);
    return $this->_restCall('GET', $resource);
 }
Sign up to request clarification or add additional context in comments.

1 Comment

Outstanding. Thank you so much. saved my sanity

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.