0

I am trying to read json provide by google drive api, but not able to read json.

i am trying to read modelData:protected data.

I got following result under $result

[0] => Google_Service_Drive_DriveFile Object (
    [modelData:protected] => Array
            (
                [labels] => Array
                    (
                        [starred] => 
                        [hidden] => 
                        [trashed] => 
                        [restricted] => 
                        [viewed] => 
                    )

                [parents] => Array
                    (
                        [0] => Array
                            (
                                [kind] => drive#parentReference
                                [id] => 0B4tddddcc03RW42UTdjUlY3SDg
                                [selfLink] => 
                                [parentLink] =>
                                [isRoot] => 
                            )

                    )

         )



)

and i am trying to read parents[0]

And i write this code

foreach ($result as $res) {

print_r($res[modelData:protected]); 
}

This gives me error

Parse error: syntax error, unexpected ':', expecting ']' in

Any idea? how to resolve this issue

Ankita Kashyap
  • 517
  • 6
  • 20

1 Answers1

0

You are posted $result object seems to be a Google_Service_Drive_DriveFile Object which is belong to google PHP library.

The rule of OOP visibility::protected says that you cannot access that protected propery outside of class(learn more about OOP Visibility concept through googling it).

if you want list of all functions releted to class you can use php get_class_methods()

print_R(get_class_methods($result));
# it will all methods available to this class.

or you can search through a library codebase for desired method which fit's your requirement.

As per the coding standards used by the Libray it's uses getters and setters for every private or protected property;

# for example if you want to access labels from above code then you can use 
$array = $result->getLabels();

# to get Parents
$parents = $result->getParents();

# if you want to set this properties you can use
$result->setLabels($array);
siddhesh
  • 598
  • 6
  • 19