I'm getting this message visiting mysite pages

warning: array_keys(): The first argument should be an array in /var/www/vhosts/visforvoltage.org/httpdocs/modules/mysite/mysite.module on line 3056.

From inspecting the code I think it's possible for $list to be uninitialized when falling out the end of the function. The initialization of

  $list = array();

should be moved to the top of the function. This would ensure that $list is initialized regardless of anything.

Comments

agentrickard’s picture

Status: Active » Postponed (maintainer needs more info)

Possibly, but I'm a bit confused by two things.

1) This code actually occurs on line 3053, not 3056.

2) Why would an empty value be passed here at all?

$list is always set to an array, because therer should be no cases in which the first IF check fails:

  if (!empty($type)) {
    $mask = mysite_get_mask($type);
    $path = drupal_get_path('module', 'mysite') .'/plugins';
    $list = array();

The function is always passed a $type parameter, so $list is always initialized.

On what page are you getting this error?

The only case in which the $list array should remain empty is if you have not activated any content types -- or if you have removed all files from one of the plugins folders -- in which case this is a configuration error, though it could be handled more gracefully.

The fix may be something like this:

  if (!empty($list)) {
    foreach ($list as $key => $value) {
      if ($type == 'styles') {
        drupal_add_css($path .'/styles/'. $value->name .'.css');
      }
      else {
        include_once($path .'/'. $type .'/'. $key . $mask);
      }
    }
    return array_keys($list);
  }
  else {
    drupal_set_message(t('Configuration error message placeholder.'), 'error');
    return NULL;
  }
}
reikiman’s picture

I was getting the message on various mysite/X/xyzzy pages. But I just changed the $list = array() line to where it had originally been, and am now not getting the message. This is with the fix I applied related to the other message.. where in mysite_get_includes I changed

$includes[$key] = file_scan_directory(...$key = 'name'...);

to

$includes[$key] = file_scan_directory(... 'name'...);

So what I'm seeing right now is the location of $list=array() may not matter, and your analysis of the flow through the function may well be correct. For myself I prefer to code defensively and to put things like this initialization outside if's so that it gets initialized regardless of any other consideration.

agentrickard’s picture

For clarity, you seem to be editing line 2990 inside function mysite_get_includes():

    $includes[$key] = file_scan_directory($dir, $mask, $nomask = array('.', '..', 'CVS'), $callback = 0, $recurse = FALSE, $key = 'name', $min_depth = 0, $depth = 0);

That change should have no effect. Listing the $key variable there is just for readability and has no effect on how the function is processed.

PHP should simply evaluate the statement and pass the result to the called function. Perhaps I am wrong and it does not.

If that syntax fails for you -- not just in Drupal, but in your PHP / server error logs -- I'd like to know what the error is. Perhaps it is a PHP configuration issue or option that you have turned on but I do not.

I do this sort of thing frequently in the code, when complex or infrequently used function are invoked. So you should also see errors for line 610:

      $rows[] = array('data' => array($owner->name, l($owner->title, 'mysite/'. $owner->uid .'/view'), format_date($updated, $type = 'medium', $format = '', $timezone = NULL)));

This would be on the page 'mysite/all'.

agentrickard’s picture

Status: Postponed (maintainer needs more info) » Active

Something similar was reported at http://drupal.org/node/208610. I suspect the real issue is about having the $key value reset.

I suspect a PHP configuration issue, since I run this without issue on both 5.1.6 and 4.4.7.

The easiest thing to do is likely to remove the $key = portion of the code above.

I would still like to know what the two configurations have in common that mine do not, so we can find the root cause. This module has been running for over a year and this is the first time this bug has been reported. Strange.

agentrickard’s picture

I see the issue here. This is newly introduced code that was designed to optimize the process of loading includes, and it has a bug in it.

The $key gets reset accidentally, and causes this error. But I still cannot replicate the error. I can create a different error if I disable all the Content Types.

Need more information to fix the issue correctly.

agentrickard’s picture

Please test the patch at http://drupal.org/node/208933

agentrickard’s picture

Status: Active » Closed (duplicate)
agentrickard’s picture

Status: Closed (duplicate) » Needs review
agentrickard’s picture

Status: Needs review » Closed (fixed)

Addressed in 5.x.2.17.

I am quite disappointed that the patch received no reviews.