Php 访问阵列中的受保护对象

Php 访问阵列中的受保护对象,php,drupal,Php,Drupal,访问body的正确语法是什么,因为这些对象不是数组,父对象是node:protected CourseObjectContent Object ( [node:protected] => stdClass Object ( [nid] => 9397 [type] => book [language] =>

访问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"
    }

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

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

类的受保护(与私有相同)成员/属性/变量不能在类外直接访问,也不能由类对象直接访问。因此,您需要为此编写一个类成员函数,以访问该类的受保护对象数组

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
}
类的受保护(与私有相同)成员/属性/变量不能在类外直接访问,也不能由类对象直接访问。因此,您需要为此编写一个类成员函数,以访问该类的受保护对象数组

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
}

继承类或父类可以访问受保护的变量/方法。只能从类访问私有变量/方法。继承类或父类可以访问受保护的变量/方法。只能从类访问私有变量/方法。