When a user clicks on any user profile other than there own this error comes up...

warning: Invalid argument supplied for foreach() in /home2/antiaddi/public_html/drupal/modules/user/user.module on line 1507.

Comments

rednikon’s picture

Also, the website is http://antiaddicts.com

tille’s picture

..same Problem with me - although it first worked so fine - now I get this same error..:|
greetz, t..

nrambeck’s picture

Version: 5.1 » 5.7

I just upgraded from 4.7.x to 5.1.7 and am getting the same error on line 1527 in user.module. Here is the code for reference:

  // Retrieve and merge all profile fields:
  foreach (module_list() as $module) {
    if ($data = module_invoke($module, 'user', 'view', '', $account)) {
      foreach ($data as $category => $items) {
        foreach ($items AS $key => $item) {
          $item['class'] = "$module-". $item['class'];
          $fields[$category][$key] = $item;
        }
      }
    }
  }

It seems the $items variable is not recognized as an array, so if I force the variable as an array like below, the error goes away.

  // Retrieve and merge all profile fields:
  foreach (module_list() as $module) {
    if ($data = module_invoke($module, 'user', 'view', '', $account)) {
      foreach ($data as $category => $items) {
        $items = (array)$items;
        foreach ($items AS $key => $item) {
          $item['class'] = "$module-". $item['class'];
          $fields[$category][$key] = $item;
        }
      }
    }
  }

But I think the ultimate solution is to look at the profile module where the array is being generated. This is from the profile_view_profile() function in the profile module:

  while ($field = db_fetch_object($result)) {
    if ($value = profile_view_field($user, $field)) {
      $title = ($field->type != 'checkbox') ? check_plain($field->title) : NULL;
      $item = array('title' => $title,
        'value' => $value,
        'class' => $field->name,
      );
      $fields[$field->category][$field->name] = $item;
    }
  }
  return $fields;

I've tried rewriting this code several ways to reform the array, but nothing seems to fix the problem. My fix in the user module doesn't address the source of the problem, so if anyone else can see the real issue please speak up.

For further reference in my scenario this is a sample array generated by the profile_view_profile() function:

Array
(
    [Personal Information] => Array
        (
            [profile_country] => Array
                (
                    [title] => Country
                    [value] => United States
                    [class] => profile_country
                )

            [profile_city] => Array
                (
                    [title] => City
                    [value] => San Francisco
                    [class] => profile_city
                )

            [profile_zip] => Array
                (
                    [title] => Zip code/postcode
                    [value] => 94114
                    [class] => profile_zip
                )

            [profile_gender] => Array
                (
                    [title] => Gender
                    [value] => female
                    [class] => profile_gender
                )

            [profile_sex] => Array
                (
                    [title] => Sexual orientation
                    [value] => straight
                    [class] => profile_sex
                )

            [profile_age] => Array
                (
                    [title] => Age range
                    [value] => 25-35
                    [class] => profile_age
                )

            [profile_bio] => Array
                (
                    [title] => Bio
                    [value] => <p>I've lived in SF for five years, and grew up in the Bay Area.</p>

                    [class] => profile_bio
                )

        )

)
dave reid’s picture

Status: Active » Postponed (maintainer needs more info)

Do you maybe have a contrib module that is improperly implementing hook_user('view')?

dpearcefl’s picture

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

Considering the lack of activity on this issue and that Drupal v5 is no longer supported by for fixes or patches, I am going to close this ticket.