Alex Borsody
Alex Borsody

Reputation: 2070

accessing protected object in array

what would be the correct syntax to access body, as these are objects not arrays and the parent objects is node:protected

 CourseObjectContent Object
    (
        [node:protected] => stdClass Object
            (
                [nid] => 9397
                [type] => book
                [language] => 
                [uid] => 1
                [status] => 1
                [created] => 1364217732
                [changed] => 1367581312
                [comment] => 0
                [promote] => 0
                [moderate] => 0
                [sticky] => 0
                [tnid] => 0
                [translate] => 0
                [vid] => 9406
                [revision_uid] => 1
                [title] => title text
                [body] => "body text"
    }

Upvotes: 1

Views: 2102

Answers (2)

Smile
Smile

Reputation: 2768

Protected (and same with Private) members/properties/variables of class are not directly accessible out of class or not accessible directly by class Object. So you need to write a Class Member Function for this to access Protected Object Array of that class

class CourseObjectContent {
    protected $node;

    //member function to access 'protected' members of class
    function accessObjectArray(){
        //TODO:Your code to access protected object array
    }
    //other member functions
}

Upvotes: 4

Harish Ambady
Harish Ambady

Reputation: 13171

You must write a function inside the class of your object to return 'body' value. Only functions belongs to the same class can access protected values of that class.

Upvotes: 2

Related Questions