我无法从对象获取数组:
请在下面查看我的代码:
print_r($product_ser_id);
打印结果:
WHMCS\Service\Service Object
(
[table:protected] => tblhosting
[columnMap:protected] => Array
(
[clientId] => userid
[productId] => packageid
[serverId] => server
[registrationDate] => regdate
[paymentGateway] => paymentmethod
[status] => domainstatus
[promotionId] => promoid
[overrideAutoSuspend] => overideautosuspend
[overrideSuspendUntilDate] => overidesuspenduntil
[bandwidthUsage] => bwusage
[bandwidthLimit] => bwlimit
[lastUpdateDate] => lastupdate
[firstPaymentAmount] => firstpaymentamount
[recurringAmount] => amount
[recurringFee] => amount
)
}
在这里,我必须从[productId]
获得价值
我已经测试为:$product_ser_id -> attributes:protected;
其显示错误为:
ParseError: syntax error, unexpected ':' in
我知道有很多例子,所以在您真正理解我的问题之前,请不要重复。
请帮助
谢谢
答案 0 :(得分:0)
问题的答案为@ {drewish
代码:
function accessProtected($obj, $prop) {
$reflection = new ReflectionClass($obj);
$property = $reflection->getProperty($prop);
$property->setAccessible(true);
return $property->getValue($obj);
}