访问数组中的受保护对象

时间:2013-05-06 04:38:35

标签: php drupal

访问body的正确语法是什么,因为这些对象不是数组,父对象是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"
    }

2 个答案:

答案 0 :(得分:4)

类的受保护(和Private相同)成员/属性/变量不能直接在类外访问,也不能由类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
}

答案 1 :(得分:2)

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

相关问题