Warning: Invalid argument supplied for foreach() in menu_unserialize() (line 400 of /var/www/kwpkrakow/includes/menu.inc).

I'm not sure what is the reason of this warning, probably it started to show when I started to use multilingual menu - but I'm not sure about it.
No matter what - here is the solution for this problem:

function menu_unserialize($data, $map) {
if ($data = unserialize($data)) {
+ if ((!is_array($data)) && (!is_object($data))) {
+ return $data;
+ }
foreach ($data as $k => $v) {
if (is_int($v)) {
$data[$k] = isset($map[$v]) ? $map[$v] : '';

Maybe it will be useful for someone.

Comments

johnv’s picture

rukayya’s picture

Invalid argument supplied for foreach() in menu_unserialize() (line 400 of C:\Documents and Settings\rukshaik\Sites\acquia-drupal\includes\menu.inc).
Can anyone tell me what is the cause of this?

aronanda’s picture

Issue summary: View changes

Also a duplicate of hook_menu path does not working.
I fixed it by including in my hook_menu:

'access callback' => TRUE,
CarlHinton’s picture

The serialization warning will disappear if you use

'access callback' => array(TRUE),
Vali Hutchison’s picture

Same applies if you use access arguments to control form access via user permissions - wrap permission(s) in an array:

'access arguments' => array('View published content'),
CProfessionals’s picture

Thank you this was exactly my issue. Obscure error. Solution hit the bulls-eye.

function my_module_menu() {
  $items = array();
  $items['pathname'] = array(
    'page callback' => 'my_module_callback',
    'access callback' => array(TRUE),
    'type' => MENU_CALLBACK,
  );
  return $items;
}
ashutosh.mishra’s picture

I have used below mentioned code . its working for me.

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