【发布时间】:2019-03-27 06:03:29
【问题描述】:
在下面的代码中,我试图以$somevariable->Userinfo->attributes(); 访问@attributes 的Userinfo,这很好,但是当没有@attributes 时,它会引发错误
在 null 上调用成员函数 attributes()
[Userinfo] => SimpleXMLElement Object
(
[@attributes] => Array
(
[UserId] => 121
[UserName] => Arun, Singh
[UserEmail] => abc@xyz.com
[CreatedDate] => 06/27/2018 08:44:21
)
)
那么,在访问@attributes之前,如何检查它是否存在?
谢谢。
【问题讨论】:
-
您能否显示 XML(而不是数组版本)和您使用的实际代码。该错误似乎表明
Userinfo不存在,而不是缺少属性。 -
是的@Nigel Ren,这就是问题所在,实际上
Userinfo我是动态从api获取的,在某些情况下我猜它没有收到。
标签: php xml properties simplexml