Hi,

I'm getting a lot of these errors in the watchdog logs:
Invalid argument supplied for foreach() /includes/menu.inc on line 258.

I have checked the arguments for the menu and I could not find any problems with the arguments for menu items - all are set up according to the d6 specs for specifying menu items.

Is something else causing this problem?

I have just updated from Drupal 5.16 to Drupal 6.10 when I noticed the errors.

I have done a search for erroneous menu items but all were using array(). All menu items are appearing properly on the site as well.

My current setup is:
Drupal 6.10
Ubuntu
Apache2
Mysql5
PHP5

Thanks

Comments

nagarajanl’s picture

Hi,

Make sure all your 'page arguments' and 'access arguments' are arrays().
(ie) 'page arguments' => array('system_admin_theme_settings'),
'access arguments' => array('access administration pages')

xano’s picture

You probably have a module with a buggy hook_menu() implementation. Please try to locate the module that causes the problem by disabling them one by one.

h3000’s picture

Hi,

Thanks for your replies.

should the code on that line be changed to add a check on the $data variable?

something like:

	if (is_array($data)) {
		foreach ($data as $k => $v) {
                      ...
                }
        }
h3000’s picture

Anyway,

I ended up modifying menu.inc to add the check before the foreach statement:

original was:

function menu_unserialize($data, $map) {
  if ($data = unserialize($data)) {
    foreach ($data as $k => $v) {
      if (is_int($v)) {
        $data[$k] = isset($map[$v]) ? $map[$v] : '';
      }
    }
    return $data;
  }
  else {
    return array();
  }
}

this was changed to:

function menu_unserialize($data, $map) {
  if ($data = unserialize($data)) {
        //check if $data is an array before running foreach
	if (is_array($data)) {
		foreach ($data as $k => $v) {
	      if (is_int($v)) {
	        $data[$k] = isset($map[$v]) ? $map[$v] : '';
	      }
	    }
	} else {
                //error with $data - output $data and $map to watchdog
		$x_map = implode(":",$map);
		watchdog("foreach error","<pre>data =" .$data . "\n map = " .$x_map. "\n</pre>", null,WATCHDOG_ERROR);
	}//end fix
    return $data;
  }
  else {
    return array();
  }
}

not sure if this should be committed but it helped a lot to track down where the problem was.

xano’s picture

Have you even read #2? This is veyr likely not a problem in the menu system, but in one of the modules you are using.

h3000’s picture

Yes I've read your comments - it was a problem with some 'page arguments' not using array() in a custom module.

But what I'm saying is that it would have been easier if the menu module had a check on the $data variable and output a more informative error message instead of letting users find out where the problem is by disabling / enabling modules one by one. This one is a huge problem especially if the site is using a lot of modules.

So I think that menu.inc line should be changed to add the check on the variable. I've seen other system modules with checks on variables before running the foreach() command - why can't this line have a check? - saves users/developers a lot of time.

xano’s picture

Status: Active » Closed (won't fix)

No, developers should read the documentation and test their code. If we are going to add checks like this to core you can kiss performance goodbye.

achilles085’s picture

this works with me http://drupal.org/node/393720#comment-1325998

THANKS!!!

arnel

Ole Martin’s picture

I had this error on 1 of 10 pages that had the same system. I discovered that the side that had the error had "Smartqueue taxonomy" active, none of the others had it. In addition, I had also disabled "Node Words - basic meta tags" . After I disabled "Smartqueue taxonomy" and enabled "Node Words" the error disappeared.

I do not have any knowledge of programming, so I do not know more than the error disappeared, not "Why"
I also tried #4 and it worked fine, but what about updates, etc. then the error will be back?

pillarsdotnet’s picture