0

I am getting the following array of objects as response when printing a variable called $userStatistic.

OnApp_User_BillingStatistics Object
        (
            [_tagRoot] => vm_stat
            [_resource] => vm_stats
            [fields:protected] => 
            [dynamicFields:protected] => Array
                (
                    [] => stdClass Object
                        (
                            [created_at] => 2012-11-01T00:00:22Z
                            [currency_code] => AUD
                            [id] => 1459

How can I parse through this and get the value of created_at and the other things.? I have tried to use $userStatistic->created_at. But it is not returning anything. Then I tried with $userStatistic[0]->created_at. But it is throwing Fatal error as

Fatal error: Cannot use object of type OnApp_User_BillingStatistics as array

How can I parse through this mixed variable ??

NB : For the other responses which don't have this square brackets after Array in dynamicFieldsm, I am able to access data using $userStatistic->created_at

air4x
  • 5,618
  • 1
  • 23
  • 36
Happy Coder
  • 4,255
  • 13
  • 75
  • 152

1 Answers1

1

It's not an array of objects, it's an object containing an array. Using -> for the object variables and [] for the array, created at is $userStatistic->dynamicFields[0]->created_at

Terje D.
  • 6,250
  • 1
  • 22
  • 30
  • it's protected, you will get a "Cannot access protected property" exception, no? – doublesharp Nov 05 '12 at 06:10
  • The dynamicFields is there in the API response as debugging is turned on. So I am not getting any value for this call. – Happy Coder Nov 05 '12 at 06:13
  • For all the other API calls its response is like `OnApp_User Object ( [_tagRoot] => user [_resource] => user [version:protected] => 3 [_release] => [dynamicFields:protected] => Array ( [_activated_at] => 2012-11-02T15:36:54+11:00 [] => [_billing_plan_id] => ` and I am accessing this as $user->_activated_at and it is displaying the correct value, But here the [] comes after Array and it makes issues – Happy Coder Nov 05 '12 at 06:19