无法访问受保护的属性PHP

时间:2016-10-10 05:33:16

标签: php arrays object

尝试从对象数组中获取值,这里是错误,到目前为止我尝试了。

echo "<pre>";print_r($response->_value());//Call to undefined method OmiseCharge::_value() 
echo "<pre>";print_r($response->_value); //Cannot access protected property PHP

实际数组

OmiseCharge Object
(
    [OMISE_CONNECTTIMEOUT:OmiseApiResource:private] => 30
    [OMISE_TIMEOUT:OmiseApiResource:private] => 60
    [_values:protected] => Array
        (
            [object] => list
            [from] => 2012-08-01T00:00:00+00:00
            [to] => 2016-10-20T00:00:00+00:00
            [offset] => 0
            [limit] => 20
            [total] => 201
            [order] => chronological
            [location] => /charges
            [data] => Array
                (
                    [0] => Array
                        (
                            [object] => charge
                            [id] => chrg_test_##############
                            [livemode] => 

2 个答案:

答案 0 :(得分:0)

 echo "<pre>";print_r($response->offsetGet('data'));

谢谢。

答案 1 :(得分:0)

要访问受保护的成员,您需要在类中实现getter方法,这是公共类型。