1

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"
    }
4

2 回答 2

4

类的受保护(与私有相同)成员/属性/变量不能直接从类外访问或不能由类 Object 直接访问。所以你需要为此编写一个类成员函数来访问该类的受保护对象数组

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
}
于 2013-05-06T05:13:52.957 回答
2

您必须在对象的类中编写一个函数以返回“body”值。只有属于同一类的函数才能访问该类的受保护值。

于 2013-05-06T04:42:26.780 回答