Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php stdClass对象、方法是否存在?_Php_Object_Stdclass - Fatal编程技术网

Php stdClass对象、方法是否存在?

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

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

我需要检查“付款”方法是否存在 我尝试使用方法\u exists如下

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'))这也起作用了!:)还是使用较长的版本更好?它更安全,因为如果
报告
可能不存在,简化的表单将导致致命的不可恢复错误。