简体   繁体   English

访问数组中的受保护对象

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

Protected (and same with Private) members/properties/variables of class are not directly accessible out of class or not accessible directly by class Object. 受保护的(与Private相同的)类的成员/属性/变量不能在类外直接访问,也不能由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
}

You must write a function inside the class of your object to return 'body' value. 您必须在对象的类内编写一个函数以返回“ body”值。 Only functions belongs to the same class can access protected values of that class. 只有属于同一类的函数才能访问该类的受保护值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM