好吧,这对我来说似乎很奇怪!
我有一个数组,其中使用用户 ID 作为数组键保存了用户对象
Array (
[75] => pwUser Object
(
[data:protected] => Array
(
[ID] => 75
[display_name] => Chris Waa
)
)
[1] => pwUser Object
(
[data:protected] => Array
(
[ID] => 1
[display_name] => Alex Müller
)
)
)
我现在想用下面的代码访问这个数组
$this->users[$notification['subscribeNotID']]->getAvatar()
但我收到一个错误
注意:未定义索引:在 NotificationList.class.php 第 217 行
致命错误:在第 217 行的 NotificationList.class.php 中的非对象上调用成员函数 getAvatar()
好的,让我们 var_dump$notification['subscribeNotID']
字符串(2)“75”
75键绝对是阵中可用的!奇怪的是,脚本是这样工作的
$ID = "75"; // var_dump() returns the same as $notification["subscribeNotID"] above
$this->users[$ID]->getAvatar()
为什么?