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.
| Comment | File | Size | Author |
|---|---|---|---|
| system-status-report.info | 3.11 KB | dzaus |
Comments
Comment #1
lxm commentedI 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.
Comment #2
merlinofchaos commentedYou 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.
Comment #3
lxm commentedHere'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
Comment #4
Heilong commentedHi everyone,
I got the same error after I activated the default taxonomy_term view. Is there any way to fix it ?
Thanks,
Comment #5
lxm commentedI 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.
Comment #6
restyler commentedhttp://drupal.org/node/383780
Comment #7
Heilong commentedHi 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.
Comment #8
stockliasteroid commentedTalk 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.
Comment #9
nirvanajyothi commentedGot 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
Comment #10
merlinofchaos commentedChecked in a fix to prevent this warning from happening to both 2.x and 3.x branches.
Comment #12
Anonymous (not verified) commentedI 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:
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:
Thanks
Comment #13
Anonymous (not verified) commentedsorry, probably not critical since I can workaround the problem.
Comment #14
hanoii+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?
Comment #15
jvieille commentedI confirm the issue and that #12 fix it
(I had to disable and enable the breaking taxonomy menu in the culprit vocabulary)
Comment #16
mwoodwar commentedThanks 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 :>)
Comment #17
startuplab commentedWell 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?
?
Comment #18
emilyf commentedThis 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)
Comment #19
ianchan commentedsubscribe
Comment #20
merlinofchaos commentedOk, 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
Comment #24
Anonymous (not verified) commentedFor 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.
and further below on line 85 add a if statement around the foreach loop
Comment #25
Anonymous (not verified) commentedComment #26
Anonymous (not verified) commentedComment #27
jmseigneur commentedI 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.
Comment #28
dawehner#24
Did you tested this already on the latest dev version?
Afaik this was fixed with this issue already.
Comment #29
esmerel commented