无法获得包含“:protected”的对象属性(Failed to get an object property that containing ":protected")

185 IT屋

I used the code below to get the object's property _items:protected, but no luck.

$obj = JSite::getMenu();
print_r($obj->_items:protected);

Object output

JMenuSite Object
(
    [_items:protected] => Array
        (
            [101] => stdClass Object
                (
                    [id] => 101
                    [menutype] => mainmenu

Anyone know what wrong with my code? Thanks.

解决方案

You are trying to access a protected property from outside the class. A protected property can only be accessed from within the class itself or classes that inherit from that class.

Read up on OOP access modifiers.

我使用下面的代码获取对象的属性 _items:protected ,但没有运气。



  $ obj = JSite :: getMenu(); 
print_r($ obj-> _items:protected);


对象输出



 < code> JMenuSite对象

[_items:protected] =>数组

[101] => stdClass对象

[id] => 101
[menutype] => mainmenu


任何人都知道我的代码有什么问题?谢谢。


解决方案

您正试图从课外访问受保护的财产。
受保护的属性只能从类本身或从该类继承的类中访问。



读取OOP访问修饰符。


本文地址:IT屋 » 无法获得包含“:protected”的对象属性