stdClass 对象,方法存在


stdClass Object, Method exists?

我正在使用SOAP与支付平台进行通信,我快到了,剩下的唯一问题是我似乎无法将来自服务器的答案转换为操作

我需要检查"付款方式"是否存在

我尝试使用method_exists

如下
if(property_exists($response, 'payment')){
    echo 'PAYMENT EXISTS';
} else {
    echo 'PAYMENT doesnt exist';
}

但它总是返回付款不存在,我做错了什么来检查吗?谢谢!

这是$response对象的print_r

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';
}