Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When I go to the list of users (or add members tab) for a group, I get an error:
warning: array_keys() [function.array-keys]: The first argument should be an array in */sites/all/modules/og/og.module on line 251.
When I add a new member, the action is successful but I get this same error shown twice.
Comments
Comment #1
moshe weitzman CreditAttribution: moshe weitzman commentedI am not seeing this. You are a standard user or site admin or group admin? Are you a member of the group in question? The page you refer to is og/users/[n]?
Comment #2
edward.peters CreditAttribution: edward.peters commentedIf you are not seeing this it may be caused by non-OG factors. But in case you have any more clues: Yes, page is og/users/[n]. Yes, I am group admin for the group (but same error if I am just site admin and not group admin). I tried making myself only a general user but still group admin, and now I get 'page not found' plus two error messages, the first is the same as already reported and the second is
warning: in_array() [function.in-array]: Wrong datatype for second argument in */sites/all/modules/og/og.module on line 253.
Also, if I go to My Groups and click on 'Edit membership' for the group of which I am Manager, I get message 'You are not authorized to access this page.' plus the already-reported line 251 error and a second error message:
warning: in_array() [function.in-array]: Wrong datatype for second argument in */all/modules/og/og.module on line 256.
The url is og/manage/[n]?destination=og%2Fmy. Same behaviour when logged in as superuser ID1 who is group administer of all groups.
Comment #3
moshe weitzman CreditAttribution: moshe weitzman commentedplease reopen if you can get this without other modules.
Comment #4
edward.peters CreditAttribution: edward.peters commentedMoshe, I have reopened this on RC4. I have disabled other OG related modules and I get the same error message reported, at top of this thread, but now refering to line 261:
warning: array_keys() [function.array-keys]: The first argument should be an array in *\sites\all\modules\og\og.module on line 261.
The errors reported in comment 2 also persist but now reference to lines 261 and 266 instead of 253 and 256.
Does this help? I realise how hard it is for you to reproduce stuff like this, so understand if this issue should be closed again. Thanks for all.
Comment #5
moshe weitzman CreditAttribution: moshe weitzman commentedComment #6
joewang CreditAttribution: joewang commentedI can confirm this problem in rc6. I find this problem strange, because when I do a print_r($user->og_groups), it outputs an array. I don't understand how the function array_keys doesn't see the data type to be an array.
When I just set $groups = array(5), the page displays fine without error.
Comment #7
joewang CreditAttribution: joewang commentedI have a quick update - the error displays only for some of the time. I tracked the issue down to the code:
around line 253. When the function user_load is called, the page displays fine. When global $user is used, the $user object does not have the og_groups variables.
Comment #8
moshe weitzman CreditAttribution: moshe weitzman commentedGood detective work. Can you put in a debug_backtrace() to know what is calling this function at that time?
Comment #9
joewang CreditAttribution: joewang commentedHere's the backtrace:
Comment #10
moshe weitzman CreditAttribution: moshe weitzman commentedDo you have aggressive caching enabled? It seems like hook_init() was skipped.
Comment #11
joewang CreditAttribution: joewang commentedI don't have any caching enabled.
Comment #12
moshe weitzman CreditAttribution: moshe weitzman commentedThe problem is globalredirect module. It is doing a menu_get_item() during hook_init() which is wreaking some havoc. I could fix this particular problem in OG but I'd rather see of GR could do things differently. You can also fix this by giving globalredirect a higher system weight than OG (see weight.module).
[file] => /var/www/html/sites/default/modules/globalredirect/globalredirect.module
[line] => 49
[function] => menu_get_item
Comment #13
roel00 CreditAttribution: roel00 commentedSame here. Doesn't really make a difference what modules are enabled, so I'm reopening the Issue.
warning: array_keys() [function.array-keys]: The first argument should be an array in C:\wamp\www\mysite\sites\all\modules\og\og.module on line 260.
I don't have the globalredirect or weight modules installed.
Comment #14
moshe weitzman CreditAttribution: moshe weitzman commentedroell0 - -can you post a backtrace as well?
Comment #15
benorgan CreditAttribution: benorgan commentedI am also getting this issue with 6.x-1.0-rc6.
The problem seems to be that in line 265;
$groups = array_keys($user->og_groups);
There is no element $user->og_groups unless $uid is set.
Any idea why this is not populated when the global $user is used?
A quick response would be appreciated, the site is going into production shortly!
Comment #16
benorgan CreditAttribution: benorgan commentedHave solved this (using a hack), as follows;
A proper solution would be good though...
Comment #17
nationalwind CreditAttribution: nationalwind commentedBenorgan,
Where would I put that hack?
Comment #18
moshe weitzman CreditAttribution: moshe weitzman commentedrestoring status. there is no great fix for this. see my comment in #12
Comment #19
benorgan CreditAttribution: benorgan commentedIn sites\all\modules\og\og.module
Comment #20
idean CreditAttribution: idean commentedThank you! Adding those 2 lines to og_is_group_member works for me in RC6.
It's not in HEAD yet. I'm not familiar with the process here, but I'd recommend a review and including it in HEAD if it passes muster, otherwise OG is very broken.
Comment #21
moshe weitzman CreditAttribution: moshe weitzman commentedI decided to add some defensive code for this similar to #16.
Comment #22
tallsimon CreditAttribution: tallsimon commented@benorgan - Thank you, works a treat.drupal communities are brilliant.
Comment #24
donquixote CreditAttribution: donquixote commentedFor anyone interested,
there is a similar thing happening in og_forum.module.
See #775362-6: og_forum: access checking fails, if menu_get_item() runs before og_init().
og_forum_group_type_load() needs to get the same cure applied.
Comment #25
rimu CreditAttribution: rimu commentedThe defensive code mentioned in #21 has a comment above it, which links to this discussion.
There is a bug in it though, where og_groups is set to an empty array sometimes.
In function og_is_group_admin, change this
to
A similar hack to og_is_group_member is needed, also.
As a general rule, I've found empty() less error-prone than isset().