从PHP中的Object获取数组值


Getting the array value from an Object in PHP

我正在尝试获取数组对象的['text']值
当我尝试打印_r($item)时,我得到的输出是:

ToDo Object
(
[data:private] => Array
    (
        [id] => 128
        [user_id] => 6785
        [view_stat] => 0
        [position] => 12
        [text] => 3rd try
        [dt_added] => 2012-07-17 04:29:08
        [tick] => 0
        [temp_view] => 6785
        [viewer] => 6785
    )
)

如何在php中获取[text]值??感谢

因为这些都是私有变量,所以不能!

您需要在类中创建一个公共函数,该函数将返回所需的特定数据:

public function getText () {
  return $this -> text;
}

在类外,你可以这样检索:

$class = new ToDo();
$myText = $class -> getText();