Php stdClass对象、方法是否存在?
我正在使用SOAP与支付平台进行通信,我就快到了,剩下的唯一问题是我似乎无法将服务器的答案转化为操作 我需要检查“付款”方法是否存在 我尝试使用方法\u exists如下Php stdClass对象、方法是否存在?,php,object,stdclass,Php,Object,Stdclass,我正在使用SOAP与支付平台进行通信,我就快到了,剩下的唯一问题是我似乎无法将服务器的答案转化为操作 我需要检查“付款”方法是否存在 我尝试使用方法\u exists如下 if(property_exists($response, 'payment')){ echo 'PAYMENT EXISTS'; } else { echo 'PAYMENT doesnt exist'; } 但它总是返回不存在的付款,我做了什么错事来检查吗?谢谢 这是$response对象的打印 stdC
if(property_exists($response, 'payment')){
echo 'PAYMENT EXISTS';
} else {
echo 'PAYMENT doesnt exist';
}
但它总是返回不存在的付款,我做了什么错事来检查吗?谢谢
这是$response对象的打印
stdClass Object
(
[statusSuccess] => stdClass Object
(
[success] => stdClass Object
(
[_] => Operation successful.
[code] => SUCCESS
)
[report] => stdClass Object
(
[approximateTotals] => stdClass Object
(
[totalRegistered] => 1500
[totalShopperPending] => 0
[totalAcquirerPending] => 0
[totalAcquirerApproved] => 1500
[totalCaptured] => 0
[totalRefunded] => 0
[totalChargedback] => 0
[exchangedTo] => EUR
[exchangeRateDate] => 2014-04-01 13:02:30
)
[payment] => stdClass Object
(
[id] => 4906949180
[paymentMethod] => MASTERCARD
[authorization] => stdClass Object
(
[status] => AUTHORIZED
[amount] => stdClass Object
(
[_] => 1500
[currency] => EUR
)
[confidenceLevel] => ACQUIRER_APPROVED
[capture] => stdClass Object
(
[status] => NEW
[amount] => stdClass Object
(
[_] => 1500
[currency] => EUR
)
)
)
)
)
)
)
试试这个:
if (
property_exists($response, 'statusSuccess')
&& property_exists($response->statusSuccess, 'report')
&& property_exists($response->statusSuccess->report, 'payment')
) {
echo 'payment method exists';
}
if(property_exists($response->statusSuccess->report'payment'){
?property_exists()需要两个参数,其中一个参数在221行的/vagrant/public/meetup.php中给出,工作正常!非常感谢!if(property_exists($response->statusSuccess->report'payment'))这也起作用了!:)还是使用较长的版本更好?它更安全,因为如果报告可能不存在,简化的表单将导致致命的不可恢复错误。