warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /u2/drupals/dcore14/sites/all/modules/chatroom/chatroom.module on line 1677.

Try explaining to a client why this message should show up on their site 506 times (yeah he counted).

they have chatroom 6.x-2.12, installed and according to them, -- as far as I can tell -- they recieved this message after user 1 was kicked and the kicking expired.

Note that the code in the referenced function:

<?php
1675
function chatroom_chat_is_kicked_user($chat_user, $node) {
1676   $key_to_check = $chat_user->uid ? $chat_user->uid : session_id();
1677   if (array_key_exists($key_to_check, $node->chat->kicked_list)) {
1678     $kicked_period = variable_get('chatroom_kicked_period', 60 * 5);
1679     $kicked_time = $node->chat->kicked_list[$key_to_check]->modified;
1680     if (($kicked_time + $kicked_period) > time()) {
1681       return TRUE;
1682     }
1683   }
1684   return FALSE;
1685 }
?>

This code uses a very sloppy coding practice: Referencing an element of an element of a node item variable without a single sanity check.

It's terrible coding style, and because it uses array_key_exists, it needs to protect users from error messages that are caused by assumptions. The code really should literally have a full sanity check and read something like:

<?php
1675
function chatroom_chat_is_kicked_user($chat_user, $node) {
1676   $key_to_check = $chat_user->uid ? $chat_user->uid : session_id();
1677   if (($node)                     &&
1678       ($node->chat)               &&
1679       ($node->chat->kicked_list)  &&
1680       (array_key_exists($key_to_check, $node->chat->kicked_list))
1681   {
1682     $kicked_period = variable_get('chatroom_kicked_period', 60 * 5);
1683     $kicked_time = $node->chat->kicked_list[$key_to_check]->modified;
1684     if (($kicked_time + $kicked_period) > time()) {
1685       return TRUE;
1686     }
1687   }
1688   return FALSE;
1689 }
?>

No time to patch, besides there are at least 10 other places in the code that make similar assumptions without any sanity checks.

Grrr.

Comments

awesome, thanks for the report and encouragement.

so, the question is why is $node->chat->kicked_list not an array?

i suspect the large number comes from an ajax poll, and somehow the node_load() called by the menu system is not working right.

can you give me anything more useful? perhaps some more kind words of encouragement because i'm not doing your work for you for free?

Sorry Justin,

I just hacked the module to make the messages stop.

I have no clue how your code is working -- or what's causing the problem in this case. But I agree with 500+ responses, it probably is some sort of polling issue.

My team just installed it and I was called in to put out the fire, ... did that and I went off to handle other fires for other clients.

From my client's perspective, now it's working, he's happy.

My team and I do appreciate this cool module, but not nearly as much as the client. Good job, and I hope you can track down the issue!

Status:Active» Postponed (maintainer needs more info)

I have just the same problem.
I have installed the chat module in a clear installation of drupal 6.20, and I have to comment the "function chatroom_chat_is_kicked_user($chat_user, $node)" to return allways false.
And for that way I get resolve the problem.
And another question I have is the next, when i write any message, word in chat, and i press enter or push Chat Button, I don´t see what I have written in the chatboard.
In any navigator....
Thanks a lot.

Pleae help me to find fix on this error.

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in chatroom_chat_is_kicked_user() (line 1955 of /sites/all/modules/chatroom/chatroom.module)

Thanks.