0

Below is my following return query from Salesforce. If i try to do $form_information[0]->Program_Type__c; I get the following errors:

Cannot use object of type stdClass as array

Below is my following array which contains an object ?. My question is how can i extract the Program_type__c and Campus_ID__c from my object and save it into variables?

print_r($form_information);



Array
    (
        [totalSize] => 1
        [done] => 1
        [records] => Array
            (
                [0] => stdClass Object
                    (
                        [attributes] => stdClass Object
                            (
                                [type] => Program_Instance__c
                                [url] => /services/data/v22.0/sobjects/Program_Instance__c/a0Ji0000001EUk9EAG
                            )

                        [Program_Type__c] => Field Science
                        [Program_Sub_type__c] => 
                        [Campus_ID__c] => a03i0000002DDBjAAO
                    )

            )

    )

the var_dump

array(3) {
  ["totalSize"]=>
  int(1)
  ["done"]=>
  bool(true)
  ["records"]=>
  array(1) {
    [0]=>
    object(stdClass)#21 (4) {
      ["attributes"]=>
      object(stdClass)#22 (2) {
        ["type"]=>
        string(19) "Program_Instance__c"
        ["url"]=>
        string(68) "/services/data/v22.0/sobjects/Program_Instance__c/a0Ji0000001EUk9EAG"
      }
      ["Program_Type__c"]=>
      string(13) "Field Science"
      ["Program_Sub_type__c"]=>
      NULL
      ["Campus_ID__c"]=>
      string(18) "a03i0000002DDBjAAO"
    }
  }
}
1
  • can you add a var_dump($form_information) to your question? Commented Jun 12, 2013 at 20:28

2 Answers 2

5

You are not traversing the object correctly.

I believe you are after something more like:

$form_information['records'][0]->Program_Type__c

However, I encourage you to read the introduction about PHP Arrays and Object Properties.

Sign up to request clarification or add additional context in comments.

2 Comments

This seems right based on the var_dump, although the error message doesn't seem to match that. Shouldn't it complain about an undefined index, not object being used as an array?
Agreed about the error. I based my answer on the print_r() output. Nonetheless, this matched the var_dump() output as well if this is indeed what the user is intending to access.
2

Try $form_information['records'][0]->Program_Type__c;

Comments

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.