PHP: 如何获取对象的受保护值?

PHP: How can I get protected values of an object?

我的电话回复了:print_r($response)

GetItemResponseType Object
(
    [Item:protected] => ItemType Object
        (
            [ApplicationData:protected] => 651034.9.3011
            [BuyerProtection:protected] => ItemEligible
            [BuyItNowPrice:protected] => AmountType Object
                (
                    [attributeValues] => Array
                        (
                            [currencyID] => EUR
                        )

                    [value:protected] => 0.0
                )

            [Country:protected] => DE

        )

)

我读了这个 (How to get protected property of object in PHP),但我无法重现解决方案。

我怎样才能得到 Country 的值,即:

   function accessProtected($obj, $prop) {
      $reflection = new ReflectionClass($obj);
      $property = $reflection->getProperty($prop);
      $property->setAccessible(true);
      return $property->getValue($obj);
    }

我什么也得不到,如果我打电话:

echo accessProtected($response, 'Country');

此致,马蒂亚斯

您应该在 class.

中创建 getter 和 setter 函数,它们是 public 或静态的

我的问题的答案是:

echo $response->Item->Country;

谢谢。