flag.module: 6.1
line 332 if (isset($node->flag)) {
line 333 foreach ($node->flag as $name => $state) {

Should probably be something like:
line 332 if (!empty($node->flag) && is_array($node->flag)) {
line 333 foreach ($node->flag as $name => $state) {

Thanks,

Comments

mooffie’s picture

Could you explain why not checking for an array causes a problem?

draco2002’s picture

Third party modules can access/modify the form array via form_alter hook and we use one that limits access to individual flags based on a users role.

I was getting reports of users with limited access getting the following warning:
“warning: Invalid argument supplied for foreach() in sites/all/modules/flag/flag.module on line 333.”

By modifying the code as mentioned in the report to verify that it is an array and has contents fixed this error. Granted it's a warning, but figured couldn't hurt to clean it up.

mooffie’s picture

Third party modules can access/modify the form array via form_alter hook

I tried to reproduce the problem (by adding '#access' => FALSE or unset()ing things in the form), but without success. I don't get a warning.

What exactly do you do to the form in your hook_alter? It's possible that your code is buggy.

I won't add an is_array() check before understanding the problem. That's because when time comes to clean up our code, we'll have to investigate the reason for every expression, and this process takes a lot of time. I prefer to do this investigation right now.

[...] but figured couldn't hurt to clean it up.

We think alike. Let me know what your form_alter does.

mooffie’s picture

Status: Active » Postponed (maintainer needs more info)
mooffie’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

I got no response.

I'm marking this "wontfix". I believe the code the user uses is buggy.