访问对象变量
我正在使用一个 API,当有数据时会产生这样的数组:
object(stdClass)#38 (5) {
["ReturnCode"]=>
int(1)
["EntityResults"]=>
object(stdClass)#39 (1) {
["Entity"]=>
object(stdClass)#40 (15) {
["id"]=>
int(43622)
["UserDefinedFields"]=>
object(stdClass)#41 (0) {
}
["TicketID"]=>
int(31024)
["InternalAllocationCodeID"]=>
int(28303142)
["Date"]=>
string(19) "2011-03-24T00:00:00"
["StartDateTime"]=>
string(19) "2011-03-24T11:41:00"
["EndDateTime"]=>
string(19) "2011-03-24T11:46:00"
["HoursWorked"]=>
float(0.08)
["HoursToBill"]=>
float(0.0833333358)
["OffsetHours"]=>
float(0)
["SummaryNotes"]=>
string(584) "Hi Steve..."
["InternalNotes"]=>
string(0) ""
["RoleID"]=>
int(24482927)
...
...
...
...
然后我有一些返回结果的记录:
object(stdClass)#33 (5) {
["ReturnCode"]=>
int(1)
["EntityResults"]=>
object(stdClass)#34 (0) {
}
["EntityResultType"]=>
string(9) "timeentry"
["Errors"]=>
object(stdClass)#35 (0) {
}
["EntityReturnInfoResults"]=>
object(stdClass)#36 (0) {
}
}
对于最后一个结果,我收到错误
永恒:通知
消息:未定义的属性: stdClass::$Entity
文件名:models/tickets_model.php
我的问题是如何避免出现此错误?我已经尝试过了
if($result->queryResult->EntityResults->Entity):
$noteso = $result->queryResult->EntityResults->Entity;
if(count($noteso)):
return $noteso;
else:
return false;
endif;
endif;
,但后来我得到了同样的错误,但在 IF 语句中。
希望这里有足够的内容让人们了解正在发生的事情。
非常感谢您的帮助,
比利
I'm using an API that results an array like this when there is data:
object(stdClass)#38 (5) {
["ReturnCode"]=>
int(1)
["EntityResults"]=>
object(stdClass)#39 (1) {
["Entity"]=>
object(stdClass)#40 (15) {
["id"]=>
int(43622)
["UserDefinedFields"]=>
object(stdClass)#41 (0) {
}
["TicketID"]=>
int(31024)
["InternalAllocationCodeID"]=>
int(28303142)
["Date"]=>
string(19) "2011-03-24T00:00:00"
["StartDateTime"]=>
string(19) "2011-03-24T11:41:00"
["EndDateTime"]=>
string(19) "2011-03-24T11:46:00"
["HoursWorked"]=>
float(0.08)
["HoursToBill"]=>
float(0.0833333358)
["OffsetHours"]=>
float(0)
["SummaryNotes"]=>
string(584) "Hi Steve..."
["InternalNotes"]=>
string(0) ""
["RoleID"]=>
int(24482927)
...
...
...
...
Then I have some record that return the results:
object(stdClass)#33 (5) {
["ReturnCode"]=>
int(1)
["EntityResults"]=>
object(stdClass)#34 (0) {
}
["EntityResultType"]=>
string(9) "timeentry"
["Errors"]=>
object(stdClass)#35 (0) {
}
["EntityReturnInfoResults"]=>
object(stdClass)#36 (0) {
}
}
With this last result I get an error
everity: Notice
Message: Undefined property:
stdClass::$EntityFilename: models/tickets_model.php
My question is how can I avoid getting this error? I've tried
if($result->queryResult->EntityResults->Entity):
$noteso = $result->queryResult->EntityResults->Entity;
if(count($noteso)):
return $noteso;
else:
return false;
endif;
endif;
But then I get the same error but in the IF statement.
Hope there's enough here for someone to understand what's happening.
Most appreciated with any help,
Billy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确的话,这就是你想要的:
If I understand correctly, this is what you want: