PHP:如何获取对象的受保护值?
我的电话回复:打印r$responsePHP:如何获取对象的受保护值?,php,ebay-api,Php,Ebay Api,我的电话回复:打印r$response GetItemResponseType Object ( [Item:protected] => ItemType Object ( [ApplicationData:protected] => 651034.9.3011 [BuyerProtection:protected] => ItemEligible [BuyItNowPrice:pr
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
)
)
我读过这篇文章,但我无法重现这个解决方案
我如何通过以下方式获得国家的价值:
function accessProtected($obj, $prop) {
$reflection = new ReflectionClass($obj);
$property = $reflection->getProperty($prop);
$property->setAccessible(true);
return $property->getValue($obj);
}
如果我打电话给:
echo accessProtected($response, 'Country');
尊敬的Matthias,您应该在类中创建公共或静态的getter和setter函数。我的问题的答案是:
echo $response->Item->Country;
谢谢。它受到保护是有原因的-很可能已经有了一个getter方法来检索此信息,您是否需要这样做是值得怀疑的。可能重复“确定”,我正在寻找此ebay api调用的getter方法。