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

moshe weitzman’s picture

Status: Active » Postponed (maintainer needs more info)

I 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]?

edward.peters’s picture

Status: Postponed (maintainer needs more info) » Active

If 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.

moshe weitzman’s picture

Status: Active » Closed (fixed)

please reopen if you can get this without other modules.

edward.peters’s picture

Version: 6.x-1.0-rc3 » 6.x-1.0-rc4
Status: Closed (fixed) » Active

Moshe, 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.

moshe weitzman’s picture

Status: Active » Postponed (maintainer needs more info)
joewang’s picture

Version: 6.x-1.0-rc4 » 6.x-1.0-rc6

I 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.

joewang’s picture

I have a quick update - the error displays only for some of the time. I tracked the issue down to the code:

  if ($uid) {
    $user = user_load(array('uid' => $uid));
  }
  else {
    global $user;
  }

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.

moshe weitzman’s picture

Good detective work. Can you put in a debug_backtrace() to know what is calling this function at that time?

joewang’s picture

Here's the backtrace:

#

Array
(
    [0] => Array
        (
            [file] => /var/www/html/includes/common.inc
            [line] => 616
            [function] => drupal_set_message
            [args] => Array
                (
                    [0] => warning: array_keys() [function.array-keys]: The first argument should be an array in /var/www/html/sites/default/modules/og/og.module on line 265.
                    [1] => error
                )

        )

    [1] => Array
        (
            [function] => drupal_error_handler
            [args] => Array
                (
                    [0] => 2
                    [1] => array_keys() [function.array-keys]: The first argument should be an array
                    [2] => /var/www/html/sites/default/modules/og/og.module
                    [3] => 265
                    [4] => Array
                        (
                            [gid] => 5
                            [include_admins] => 1
                            [uid] => 
                            [user] => stdClass Object
                                (
                                    [uid] => 1
                                    [name] => Admin
                                    [pass] => 2884e57d0bde9522259a3dc9c8565ee3
                                    [mail] => me@joewang.net
                                    [mode] => 0
                                    [sort] => 0
                                    [threshold] => 0
                                    [theme] => reserve
                                    [signature] => 
                                    [created] => 1220727930
                                    [access] => 1221759533
                                    [login] => 1221756865
                                    [status] => 1
                                    [timezone] => -14400
                                    [language] => 
                                    [picture] => 
                                    [init] => me@joewang.net
                                    [data] => a:1:{s:13:"form_build_id";s:37:"form-9ed0c211bff358048b5ec46e66884cc9";}
                                    [timezone_name] => America/New_York
                                    [sid] => i44jd247c383qpmbmlm5rmddo4
                                    [hostname] => 10.1.151.210
                                    [timestamp] => 1221759552
                                    [cache] => 0
                                    [session] => og_last|O:8:"stdClass":39:{s:3:"nid";s:1:"5";s:4:"type";s:12:"organization";s:8:"language";s:0:"";s:3:"uid";s:1:"1";s:6:"status";s:1:"1";s:7:"created";s:10:"1220844259";s:7:"changed";s:10:"1220894795";s:7:"comment";s:1:"0";s:7:"promote";s:1:"0";s:8:"moderate";s:1:"0";s:6:"sticky";s:1:"0";s:4:"tnid";s:1:"0";s:9:"translate";s:1:"0";s:3:"vid";s:1:"5";s:12:"revision_uid";s:1:"1";s:5:"title";s:7:"Reserve";s:4:"body";s:0:"";s:6:"teaser";s:0:"";s:3:"log";s:0:"";s:18:"revision_timestamp";s:10:"1220894795";s:6:"format";s:1:"4";s:4:"name";s:5:"Admin";s:7:"picture";s:0:"";s:4:"data";s:72:"a:1:{s:13:"form_build_id";s:37:"form-9ed0c211bff358048b5ec46e66884cc9";}";s:4:"path";s:7:"reserve";s:12:"og_selective";s:1:"3";s:14:"og_description";s:23:"Western Reserve Academy";s:8:"og_theme";s:0:"";s:11:"og_register";s:1:"0";s:12:"og_directory";s:1:"0";s:15:"og_notification";s:1:"0";s:11:"og_language";s:0:"";s:10:"og_private";s:1:"0";s:9:"_workflow";b:0;s:15:"og_vocabularies";a:0:{}s:22:"last_comment_timestamp";s:10:"1220844259";s:17:"last_comment_name";N;s:13:"comment_count";s:1:"0";s:8:"taxonomy";a:0:{}}node_overview_filter|a:0:{}views|a:1:{s:8:"calendar";a:1:{s:7:"default";a:1:{s:3:"tid";s:3:"All";}}}updates_remaining|a:0:{}
                                    [form_build_id] => form-9ed0c211bff358048b5ec46e66884cc9
                                    [roles] => Array
                                        (
                                            [2] => authenticated user
                                        )

                                )

                        )

                )

        )

    [2] => Array
        (
            [file] => /var/www/html/sites/default/modules/og/og.module
            [line] => 265
            [function] => array_keys
            [args] => Array
                (
                    [0] => 
                )

        )

    [3] => Array
        (
            [file] => /var/www/html/sites/default/modules/og/og.module
            [line] => 239
            [function] => og_is_group_member
            [args] => Array
                (
                    [0] => 5
                )

        )

    [4] => Array
        (
            [function] => og_menu_access_picture
            [args] => Array
                (
                    [0] => 5
                )

        )

    [5] => Array
        (
            [file] => /var/www/html/includes/menu.inc
            [line] => 450
            [function] => call_user_func_array
            [args] => Array
                (
                    [0] => og_menu_access_picture
                    [1] => Array
                        (
                            [0] => 5
                        )

                )

        )

    [6] => Array
        (
            [file] => /var/www/html/includes/menu.inc
            [line] => 572
            [function] => _menu_check_access
            [args] => Array
                (
                    [0] => Array
                        (
                            [path] => og/users/%/faces
                            [load_functions] => Array
                                (
                                    [2] => 
                                )

                            [to_arg_functions] => 
                            [access_callback] => og_menu_access_picture
                            [access_arguments] => a:1:{i:0;i:2;}
                            [page_callback] => views_page
                            [page_arguments] => a:3:{i:0;s:16:"og_members_faces";i:1;s:7:"default";i:2;i:2;}
                            [fit] => 13
                            [number_parts] => 4
                            [tab_parent] => og/users/%
                            [tab_root] => og/users/%
                            [title] => Faces
                            [title_callback] => t
                            [title_arguments] => 
                            [type] => 128
                            [block_callback] => 
                            [description] => 
                            [position] => 
                            [weight] => 0
                            [file] => 
                            [href] => og/users/5/faces
                            [options] => Array
                                (
                                )

                        )

                    [1] => Array
                        (
                            [0] => og
                            [1] => users
                            [2] => 5
                            [3] => faces
                        )

                )

        )

    [7] => Array
        (
            [file] => /var/www/html/includes/menu.inc
            [line] => 316
            [function] => _menu_translate
            [args] => Array
                (
                    [0] => Array
                        (
                            [path] => og/users/%/faces
                            [load_functions] => Array
                                (
                                    [2] => 
                                )

                            [to_arg_functions] => 
                            [access_callback] => og_menu_access_picture
                            [access_arguments] => a:1:{i:0;i:2;}
                            [page_callback] => views_page
                            [page_arguments] => a:3:{i:0;s:16:"og_members_faces";i:1;s:7:"default";i:2;i:2;}
                            [fit] => 13
                            [number_parts] => 4
                            [tab_parent] => og/users/%
                            [tab_root] => og/users/%
                            [title] => Faces
                            [title_callback] => t
                            [title_arguments] => 
                            [type] => 128
                            [block_callback] => 
                            [description] => 
                            [position] => 
                            [weight] => 0
                            [file] => 
                            [href] => og/users/5/faces
                            [options] => Array
                                (
                                )

                        )

                    [1] => Array
                        (
                            [0] => og
                            [1] => users
                            [2] => 5
                            [3] => faces
                        )

                )

        )

    [8] => Array
        (
            [file] => /var/www/html/sites/default/modules/globalredirect/globalredirect.module
            [line] => 49
            [function] => menu_get_item
            [args] => Array
                (
                )

        )

    [9] => Array
        (
            [function] => globalredirect_init
            [args] => Array
                (
                )

        )

    [10] => Array
        (
            [file] => /var/www/html/includes/module.inc
            [line] => 471
            [function] => call_user_func_array
            [args] => Array
                (
                    [0] => globalredirect_init
                    [1] => Array
                        (
                        )

                )

        )

    [11] => Array
        (
            [file] => /var/www/html/includes/common.inc
            [line] => 2463
            [function] => module_invoke_all
            [args] => Array
                (
                    [0] => init
                )

        )

    [12] => Array
        (
            [file] => /var/www/html/includes/bootstrap.inc
            [line] => 1028
            [function] => _drupal_bootstrap_full
            [args] => Array
                (
                )

        )

    [13] => Array
        (
            [file] => /var/www/html/includes/bootstrap.inc
            [line] => 939
            [function] => _drupal_bootstrap
            [args] => Array
                (
                    [0] => 8
                )

        )

    [14] => Array
        (
            [file] => /var/www/html/index.php
            [line] => 16
            [function] => drupal_bootstrap
            [args] => Array
                (
                    [0] => 8
                )

        )

)

# warning: array_keys() [function.array-keys]: The first argument should be an array in /var/www/html/sites/default/modules/og/og.module on line 265.

Array
(
    [0] => Array
        (
            [file] => /var/www/html/includes/common.inc
            [line] => 616
            [function] => drupal_set_message
            [args] => Array
                (
                    [0] => warning: array_keys() [function.array-keys]: The first argument should be an array in /var/www/html/sites/default/modules/og/og.module on line 265.
                    [1] => error
                )

        )

    [1] => Array
        (
            [function] => drupal_error_handler
            [args] => Array
                (
                    [0] => 2
                    [1] => array_keys() [function.array-keys]: The first argument should be an array
                    [2] => /var/www/html/sites/default/modules/og/og.module
                    [3] => 265
                    [4] => Array
                        (
                            [gid] => 5
                            [include_admins] => 1
                            [uid] => 
                            [user] => stdClass Object
                                (
                                    [uid] => 1
                                    [name] => Admin
                                    [pass] => 2884e57d0bde9522259a3dc9c8565ee3
                                    [mail] => me@joewang.net
                                    [mode] => 0
                                    [sort] => 0
                                    [threshold] => 0
                                    [theme] => reserve
                                    [signature] => 
                                    [created] => 1220727930
                                    [access] => 1221759533
                                    [login] => 1221756865
                                    [status] => 1
                                    [timezone] => -14400
                                    [language] => 
                                    [picture] => 
                                    [init] => me@joewang.net
                                    [data] => a:1:{s:13:"form_build_id";s:37:"form-9ed0c211bff358048b5ec46e66884cc9";}
                                    [timezone_name] => America/New_York
                                    [sid] => i44jd247c383qpmbmlm5rmddo4
                                    [hostname] => 10.1.151.210
                                    [timestamp] => 1221759552
                                    [cache] => 0
                                    [session] => og_last|O:8:"stdClass":39:{s:3:"nid";s:1:"5";s:4:"type";s:12:"organization";s:8:"language";s:0:"";s:3:"uid";s:1:"1";s:6:"status";s:1:"1";s:7:"created";s:10:"1220844259";s:7:"changed";s:10:"1220894795";s:7:"comment";s:1:"0";s:7:"promote";s:1:"0";s:8:"moderate";s:1:"0";s:6:"sticky";s:1:"0";s:4:"tnid";s:1:"0";s:9:"translate";s:1:"0";s:3:"vid";s:1:"5";s:12:"revision_uid";s:1:"1";s:5:"title";s:7:"Reserve";s:4:"body";s:0:"";s:6:"teaser";s:0:"";s:3:"log";s:0:"";s:18:"revision_timestamp";s:10:"1220894795";s:6:"format";s:1:"4";s:4:"name";s:5:"Admin";s:7:"picture";s:0:"";s:4:"data";s:72:"a:1:{s:13:"form_build_id";s:37:"form-9ed0c211bff358048b5ec46e66884cc9";}";s:4:"path";s:7:"reserve";s:12:"og_selective";s:1:"3";s:14:"og_description";s:23:"Western Reserve Academy";s:8:"og_theme";s:0:"";s:11:"og_register";s:1:"0";s:12:"og_directory";s:1:"0";s:15:"og_notification";s:1:"0";s:11:"og_language";s:0:"";s:10:"og_private";s:1:"0";s:9:"_workflow";b:0;s:15:"og_vocabularies";a:0:{}s:22:"last_comment_timestamp";s:10:"1220844259";s:17:"last_comment_name";N;s:13:"comment_count";s:1:"0";s:8:"taxonomy";a:0:{}}node_overview_filter|a:0:{}views|a:1:{s:8:"calendar";a:1:{s:7:"default";a:1:{s:3:"tid";s:3:"All";}}}updates_remaining|a:0:{}
                                    [form_build_id] => form-9ed0c211bff358048b5ec46e66884cc9
                                    [roles] => Array
                                        (
                                            [2] => authenticated user
                                        )

                                )

                        )

                )

        )

    [2] => Array
        (
            [file] => /var/www/html/sites/default/modules/og/og.module
            [line] => 265
            [function] => array_keys
            [args] => Array
                (
                    [0] => 
                )

        )

    [3] => Array
        (
            [file] => /var/www/html/sites/default/modules/og/og.module
            [line] => 239
            [function] => og_is_group_member
            [args] => Array
                (
                    [0] => 5
                )

        )

    [4] => Array
        (
            [function] => og_menu_access_picture
            [args] => Array
                (
                    [0] => 5
                )

        )

    [5] => Array
        (
            [file] => /var/www/html/includes/menu.inc
            [line] => 450
            [function] => call_user_func_array
            [args] => Array
                (
                    [0] => og_menu_access_picture
                    [1] => Array
                        (
                            [0] => 5
                        )

                )

        )

    [6] => Array
        (
            [file] => /var/www/html/sites/default/modules/globalredirect/globalredirect.module
            [line] => 50
            [function] => _menu_check_access
            [args] => Array
                (
                    [0] => Array
                        (
                            [path] => og/users/%/faces
                            [load_functions] => Array
                                (
                                    [2] => 
                                )

                            [to_arg_functions] => 
                            [access_callback] => og_menu_access_picture
                            [access_arguments] => a:1:{i:0;i:2;}
                            [page_callback] => views_page
                            [page_arguments] => Array
                                (
                                    [0] => og_members_faces
                                    [1] => default
                                    [2] => 5
                                )

                            [fit] => 13
                            [number_parts] => 4
                            [tab_parent] => og/users/%
                            [tab_root] => og/users/%
                            [title] => Faces
                            [title_callback] => t
                            [title_arguments] => 
                            [type] => 128
                            [block_callback] => 
                            [description] => 
                            [position] => 
                            [weight] => 0
                            [file] => 
                            [href] => og/users/5/faces
                            [options] => Array
                                (
                                )

                            [access] => 1
                            [localized_options] => Array
                                (
                                )

                            [map] => Array
                                (
                                    [0] => og
                                    [1] => users
                                    [2] => 5
                                    [3] => faces
                                )

                        )

                    [1] => Array
                        (
                            [0] => og
                            [1] => users
                            [2] => 5
                            [3] => faces
                        )

                )

        )

    [7] => Array
        (
            [function] => globalredirect_init
            [args] => Array
                (
                )

        )

    [8] => Array
        (
            [file] => /var/www/html/includes/module.inc
            [line] => 471
            [function] => call_user_func_array
            [args] => Array
                (
                    [0] => globalredirect_init
                    [1] => Array
                        (
                        )

                )

        )

    [9] => Array
        (
            [file] => /var/www/html/includes/common.inc
            [line] => 2463
            [function] => module_invoke_all
            [args] => Array
                (
                    [0] => init
                )

        )

    [10] => Array
        (
            [file] => /var/www/html/includes/bootstrap.inc
            [line] => 1028
            [function] => _drupal_bootstrap_full
            [args] => Array
                (
                )

        )

    [11] => Array
        (
            [file] => /var/www/html/includes/bootstrap.inc
            [line] => 939
            [function] => _drupal_bootstrap
            [args] => Array
                (
                    [0] => 8
                )

        )

    [12] => Array
        (
            [file] => /var/www/html/index.php
            [line] => 16
            [function] => drupal_bootstrap
            [args] => Array
                (
                    [0] => 8
                )

        )

)
moshe weitzman’s picture

Do you have aggressive caching enabled? It seems like hook_init() was skipped.

joewang’s picture

I don't have any caching enabled.

moshe weitzman’s picture

Status: Postponed (maintainer needs more info) » Fixed

The 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

roel00’s picture

Status: Fixed » Active

Same 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.

moshe weitzman’s picture

roell0 - -can you post a backtrace as well?

benorgan’s picture

I 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!

benorgan’s picture

Have solved this (using a hack), as follows;

function og_is_group_member($gid, $include_admins = TRUE, $uid = NULL) {
  if ($uid) {
    $user = user_load(array('uid' => $uid));  
  }
  else {
    global $user; 
    $user_temp = $user;
    $user = user_load(array('uid' => $user_temp->uid));    
  }

  // Allow caller to pass in a full $node. Used by menu items.
  if (is_object($gid)) {
    $gid = $gid->nid;
  }

  $groups = array_keys($user->og_groups);
  if ($include_admins) {
    return user_access('administer nodes', $user) || in_array($gid, $groups) ? TRUE : FALSE;
  }
  else {
    return in_array($gid, $groups) ? TRUE : FALSE;
  }
}

A proper solution would be good though...

nationalwind’s picture

Benorgan,

Where would I put that hack?

moshe weitzman’s picture

Status: Active » Fixed

restoring status. there is no great fix for this. see my comment in #12

benorgan’s picture

In sites\all\modules\og\og.module

idean’s picture

Status: Fixed » Needs review

Thank 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.

moshe weitzman’s picture

Status: Needs review » Fixed

I decided to add some defensive code for this similar to #16.

tallsimon’s picture

@benorgan - Thank you, works a treat.drupal communities are brilliant.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

donquixote’s picture

For 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.

rimu’s picture

Version: 6.x-1.0-rc6 » 6.x-2.4
Status: Closed (fixed) » Needs work

The 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

if ($account->uid && !isset($account->og_groups)) {
    // Reload the user object.
    $account = user_load($account->uid);
  }

to

if ($account->uid || empty($account->og_groups)) {
    // Reload the user object.
    $account = user_load($account->uid);
  }

A similar hack to og_is_group_member is needed, also.

As a general rule, I've found empty() less error-prone than isset().