1

这看起来很笨拙:

if (empty($xml['soap:Envelope']['soap:Body']['SendPurchasesResponse']['PurchasesResponse']['Status']['Code'])) {
    $status = $xml['soap:Envelope']['soap:Body']['SendPurchasesResponse']['PurchasesResponse']['Status']['Code'];
}

如果缺少某些数组键,是否有更好的方法来处理“未定义索引”错误?正如您可能猜到的那样,这个数组来自基于 XML 的 API,我无法相信他们对我的响应。

您是否认为使用“@”来抑制错误是一种逃避:

$status = @$xml['soap:Envelope']['soap:Body']['SendPurchasesResponse']['PurchasesResponse']['Status']['Code'];
4

1 回答 1

0

这对你有什么作用?

try {
  $status = $xml['soap:Envelope']['soap:Body']['SendPurchasesResponse']['PurchasesResponse']['Status']['Code'];
} catch (Exception $e) {
  $status = ""
}
于 2012-05-10T19:13:12.470 回答