I never noticed this before, but I recently looked at the database logs (admin/reports/dblog) and I discovered a lot of php errors being reported. The errors don't seem to be affecting expected functionality or causing any apparent breakage, which is why I never thought to look. It seems that any time I hit the 'edit' button for a node or a menu (but not taxonomies, or 'config' on blocks, etc) I get three repetitions each of the following errors:

Invalid argument supplied for foreach() in ...sites\all\modules\views\includes\handlers.inc on line 807.
Invalid argument supplied for foreach() in ...includes\common.inc on line 1597.

Looking at those files, I see:

handlers.inc (including whole 'offending' method, line 807 indicated below)

function views_break_phrase($str, $filter = NULL) {
  if (!$filter) {
    $filter = new stdClass();
  }
  if (preg_match('/^([0-9]+[+ ])+[0-9]+$/', $str)) {
    // The '+' character in a query string may be parsed as ' '.
    $filter->operator = 'or';
    $filter->value = preg_split('/[+ ]/', $str);
  }
  else if (preg_match('/^([0-9]+,)*[0-9]+$/', $str)) {
    $filter->operator = 'and';
    $filter->value = explode(',', $str);
  }

  // Keep an 'error' value if invalid strings were given.
  if (!empty($str) && (empty($filter->value) || !is_array($filter->value))) {
    $filter->value = array(-1);
    return $filter;
  }

  // Doubly ensure that all values are numeric only.
  foreach ($filter->value as $id => $value) {	//// ---- line 807 ----
    $filter->value[$id] = intval($value);
  }

common.inc

function drupal_map_assoc($array, $function = NULL) {
  if (!isset($function)) {
    $result = array();
    foreach ($array as $value) {	//// ---- line 1597 ----
      $result[$value] = $value;
    }
    return $result;
  }
//... code continues below here

To try to see what was going on, I put in some error messages like so:

	if (!is_array($filter->value))
		//in handlers.inc right before the 'offending line'
		drupal_set_message('views_break_phrase not array when str(' . $str . '): [' . print_r($filter, TRUE) . ']', 'error', FALSE);
		//in common.inc right before the 'offending line'
		drupal_set_message('map_assoc not array in func(' . $function . '): [' . print_r($array, TRUE) . ']', 'error', FALSE);

which returns empty results every time:

    * views_break_phrase not array when str(): [stdClass Object ( [value] => ) ]
    * map_assoc not array in func(): []

I tried making a completely basic content type with no fancy fields added, and it still gets the same errors (6, 3 each). Would this have something to do with creating values for select lists? If so, the only select list I see in the new content type is under the 'Menu Settings'.

So where does 'views' come into play when editing a node, what is looking for an empty argument to split (should it be checking for this?), and why is it trying to map an empty array? Can anyone else reproduce this error? Not really sure how to track this down farther...

Testing on XAMPP (1.6.8) under Windows.
Thanks to this patch, system settings attached.

CommentFileSizeAuthor
system-status-report.info3.11 KBdzaus

Comments

lxm’s picture

Version: 6.x-2.3 » 6.x-2.4

I have similar issue. I get 1597 error and 807 error which display on the page. When I disable the Views module, the errors go away, but I'd rather not disable the views module.

merlinofchaos’s picture

You might try performing a vsm_trace() there as well (you need devel.module for that to function) to see what is calling views_break_phrase() with the empty value.

lxm’s picture

Version: 6.x-2.4 » 6.x-2.5

Here's trace on 807 error:

views_plugin_argument_validate_taxonomy_term.inc: drupal_map_assoc line 82
views_handler_argument.inc: views_plugin_argument_validate_taxonomy_term->validate_argument line 638
views_handler_argument.inc: views_handler_argument->validate_arg line 658
views.module: views_handler_argument->validate_argument line 269
menu.inc: call_user_func_array line 407
menu.inc: _menu_load_objects line 653
menu.inc: _menu_link_translate line 1010
menu.inc: _menu_tree_check_access line 999
menu.inc: menu_tree_check_access line 948
menu.inc: menu_tree_page_data line 1253
menu.inc: menu_navigation_links line 1218
theme.inc: menu_primary_links line 1811
theme.inc: call_user_func_array line 658
index.php: theme line 36

Here's trace of 1597 error:

#

views_plugin_argument_validate_taxonomy_term.inc: views_break_phrase line 75
views_handler_argument.inc: views_plugin_argument_validate_taxonomy_term->validate_argument line 638
views_handler_argument.inc: views_handler_argument->validate_arg line 658
views.module: views_handler_argument->validate_argument line 269
menu.inc: call_user_func_array line 407
menu.inc: _menu_load_objects line 653
menu.inc: _menu_link_translate line 1010
menu.inc: _menu_tree_check_access line 999
menu.inc: menu_tree_check_access line 948
menu.inc: menu_tree_page_data line 719
menu.module: menu_tree line 288
module.inc: call_user_func_array line 450
block.module: module_invoke line 473
theme.inc: block_list line 1571
theme.inc: call_user_func_array line 617
theme.inc: theme line 1765
theme.inc: call_user_func_array line 658
index.php: theme line 36

Heilong’s picture

Hi everyone,
I got the same error after I activated the default taxonomy_term view. Is there any way to fix it ?
Thanks,

lxm’s picture

I made the errors go away by enclosing the foreach loops in if(!empty($value)){}.

One change in handlers.inc in views and one change in includes/common.inc

I have no idea if this is a good solution or not.

restyler’s picture

Heilong’s picture

Hi everyone,

I got the same problem after activating the default view taxonomy_term, I post again because I still didn't find any solution for it.
Here are the errors I got :

* warning: Invalid argument supplied for foreach() in (...)/sites/all/modules/views/includes/handlers.inc on line 807.
* warning: Invalid argument supplied for foreach() in (...)/includes/common.inc on line 1606.
* warning: Invalid argument supplied for foreach() in (...)/sites/all/modules/views/includes/handlers.inc on line 807.
* warning: Invalid argument supplied for foreach() in (...)/includes/common.inc on line 1606.

By the way I disabled and uninstalled the Pathauto and Taxonomy menu module, and I still have the warnings displayed.

stockliasteroid’s picture

Talk about a non-obvious fix...

Here's what caused my issue:
Pathauto bug referenced here: http://drupal.org/node/314697 caused for a bunch of incorrect aliases to be generated. (Fixed in dev version of pathauto)
When I updated a menu item that pointed to a taxonomy term, because of the incorrect system path generated by Pathauto, the menu system set the path of the menu item to "taxonomy/term/". After that, the error described above would occur on EVERY PAGE OF THE SITE.

I tore my hair out for a while, thinking "All I did was update a menu item!", updated pathauto, regenerated all my taxonomy aliases, and the problem persisted. I finally re-checked the menu item that started things off, saw the URL that menu had used, replaced it with the correct one, and all was well.

nirvanajyothi’s picture

Got the same error. More people may be havin. Please make the new release soon.

edit: sorry, accidently wrote this here instead of the Pathauto queue.

-thank you

merlinofchaos’s picture

Status: Active » Fixed

Checked in a fix to prevent this warning from happening to both 2.x and 3.x branches.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Priority: Normal » Critical

I am not sure whether to create a new new issue or re-opening this one. Please excuse me if I did not follow the right procedure.

I just installed the 6.x-2.x-dev (2009-Jul-02) but I still got the error:
warning: Invalid argument supplied for foreach() in /includes/common.inc on line 1607.
Not only when editing nodes and menus but also when viewing pages. Maybe the title of the topic should be changed?

I have put in a vsm_trace() in common.inc:

function drupal_map_assoc($array, $function = NULL) {
  
  if (!isset($function)) {
    vsm_trace();
    $result = array();
    foreach ($array as $value) {
      $result[$value] = $value;
    }
    return $result;
  }
  elseif (function_exists($function)) {
    $result = array();
    foreach ($array as $value) {
      $result[$value] = $function($value);
    }
    return $result;
  }
}

Below is the result:

views_plugin_argument_validate_taxonomy_term.inc: drupal_map_assoc line 82
views_handler_argument.inc: views_plugin_argument_validate_taxonomy_term->validate_argument line 648
views_handler_argument.inc: views_handler_argument->validate_arg line 668
views.module: views_handler_argument->validate_argument line 269
menu.inc: call_user_func_array line 407
menu.inc: _menu_load_objects line 657
menu.inc: _menu_link_translate line 1025
menu.inc: _menu_tree_check_access line 1028
menu.inc: _menu_tree_check_access line 1014
menu.inc: menu_tree_check_access line 952
menu.inc: menu_tree_page_data line 1268
menu.inc: menu_navigation_links line 1233
theme.inc: menu_primary_links line 1820
theme.inc: call_user_func_array line 658
index.php: theme line 36

For now I can work around the problem by checking if $tids->value is an array in views_plugin_argument_validate_taxonomy_term.inc on line 82:

if (is_array($tids->value)) {
  $test = drupal_map_assoc($tids->value);
}

Thanks

Anonymous’s picture

Version: 6.x-2.5 » 6.x-2.x-dev
Status: Closed (fixed) » Active

sorry, probably not critical since I can workaround the problem.

hanoii’s picture

Priority: Critical » Normal

+1 for workaround in #12. I can confirm it works.

By looking a little bit more on the code, it seems that this may be fixed instead in the views_break_phrase(). As I really don't know for sure the whole views code to properly decide a fix on that one I wasn't able to provide a patch, but I do think that the function should return array(-1) so the taxonomy validation won't throw this warning. Basically, is it OK for views_break_phrase() to return in the $filter->value something other than arrays?

jvieille’s picture

I confirm the issue and that #12 fix it
(I had to disable and enable the breaking taxonomy menu in the culprit vocabulary)

mwoodwar’s picture

Thanks for mentioning the enable/disable part, I chose the 'select to rebuild menu on submit' from the edit vocabulary page...and finally (after almost three hours!!!) It is fixed.

This is the kind of thing that drives me CRAZY about Drupal...I love to hate it...or hate to love it...not sure which :>)

startuplab’s picture

Well i tried the workaround at 12, and it solved the error problem but now i'm having an issue when i go to add a product. Even when i select a category (taxonomy) keyword it is spitting out an error that a catalog field is required. Any idea how to fix?
?

emilyf’s picture

This is still a problem when enabling default taxonomy view and excluding certain node types from it. it results in
Invalid argument supplied for foreach() in ...sites\all\modules\views\includes\handlers.inc on line 807.
Invalid argument supplied for foreach() in ...includes\common.inc on line 1597.

I found a patch in #9 of this issue: http://drupal.org/node/411566#comment-1565828

that does appear to fix it (go to link above to get the patch)

ianchan’s picture

subscribe

merlinofchaos’s picture

Status: Active » Fixed

Ok, this only was an issue when 0 is given as an argument. Frankly that's probably a bug in taxonomy_menu -- 0 should never be a valid argument. However, Views should react more nicely when this invalid value appears. Fixed in 2.x and 3.x

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Version: 6.x-2.x-dev » 6.x-2.11
Priority: Normal » Critical
Status: Closed (fixed) » Active

For some reason this problem has shown up again. Taxonomy menu is not in use.

Workaround:
in file views_plugin_argument_validate_taxonomy_term.inc on line 80 check if it is an array.

        if (is_array($tids->value)) {
          $test = drupal_map_assoc($tids->value);
        }

and further below on line 85 add a if statement around the foreach loop

        if ($test) {
          foreach ($test as $tid) {
            if (isset($validated_cache[$tid])) {
              if ($validated_cache[$tid] === FALSE) {
                return FALSE;
              }
              else {
                $titles[] = $validated_cache[$tid];
                unset($test[$tid]);
              }
            }
          }
        }
Anonymous’s picture

Title: "Invalid Argument supplied for foreach" - when editing nodes and menus » "Invalid Argument supplied for foreach"
Anonymous’s picture

Title: "Invalid Argument supplied for foreach" » "Invalid Argument supplied for foreach" in common.inc
jmseigneur’s picture

I had a related issue " Invalid argument supplied for foreach() in drupal_map_assoc() (line 1646 ..." with 6.x-2.11 moved to 6.x-3.x-dev (2010-Oct-01) applied the fix in #24 and it seems to work. However it is not clear why this issue appeared. I had updated to 6.x-2.11 a few days before the issue happens and did not notice a problem for the first few days.

dawehner’s picture

Priority: Critical » Normal
Status: Active » Postponed (maintainer needs more info)

#24

Did you tested this already on the latest dev version?

Afaik this was fixed with this issue already.

esmerel’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)