Drupal 7: Duplicated and Extended values on hook_preprocess by Drupal I'm trying to pass variables from my module to a template. Everything is working fine, but the variables passed to the view appear to be modificated.

Callback to generate and fill the view:

 function mycallback() {
    //(...)
      //var_dump($members); 
      return theme('team_members', $members);
    }


Contents of $members:

array
  0 =&gt; 
    object(stdClass)[55]
      public 'mid' =&gt; string '1' (length=1)
      public 'name' =&gt; string 'LLUIS' (length=5)
  1 =&gt; 
    object(stdClass)[18]
      public 'mid' =&gt; string '2' (length=1)
      public 'name' =&gt; string 'OSCAR' (length=5) 


This is the hook:

function global_preprocess_team_members(&amp;$variables) {
  //var_dump($variables); 
  $variables['members'] = $variables;
}


The content of $members is the following one:

array
  0 =&gt; 
    object(stdClass)[55]
      public 'mid' =&gt; string '1' (length=1)
      public 'name' =&gt; string 'LLUIS' (length=5)
  1 =&gt; 
    object(stdClass)[18]
      public 'mid' =&gt; string '2' (length=1)
      public 'name' =&gt; string 'OSCAR' (length=5)
  'content' =&gt; null
  'theme_hook_suggestions' =&gt; 
    array
      empty


Somehow, content, theme_hook_suggestions has been added to the array, but there is more.

Finally, when I print the results on the template file (tpl.php) via var_dump() again:

array
  0 =&gt; 
    object(stdClass)[55]
      public 'mid' =&gt; string '1' (length=1)
      public 'name' =&gt; string 'LLUIS' (length=5)
  1 =&gt; 
    object(stdClass)[18]
      public 'mid' =&gt; string '2' (length=1)
      public 'name' =&gt; string 'OSCAR' (length=5)
  'content' =&gt; null
  'theme_hook_suggestions' =&gt; 
    array
      empty
  'members' =&gt; 
    array
      0 =&gt; 
        object(stdClass)[55]
          public 'mid' =&gt; string '1' (length=1)
          public 'name' =&gt; string 'LLUIS' (length=5)
      1 =&gt; 
        object(stdClass)[18]
          public 'mid' =&gt; string '2' (length=1)
          public 'name' =&gt; string 'OSCAR' (length=5)
      'content' =&gt; null
      'theme_hook_suggestions' =&gt; 
        array
          empty
      'members' =&gt; 
        &amp;array
  'zebra' =&gt; string 'odd' (length=3)
  'id' =&gt; int 1
  'directory' =&gt; string 'sites/all/themes/global' (length=23)
  'classes_array' =&gt; 
    array
      0 =&gt; string 'team-members' (length=12)
  'attributes_array' =&gt; 
    array
      empty
  'title_attributes_array' =&gt; 
    array
      empty
  'content_attributes_array' =&gt; 
    array
      empty
  'title_prefix' =&gt; 
    array
      empty
  'title_suffix' =&gt; 
    array
      empty
  'user' =&gt; 
    object(stdClass)[9]
      (...)
  'db_is_active' =&gt; boolean true
  'is_admin' =&gt; boolean true
  'logged_in' =&gt; boolean true
  'is_front' =&gt; boolean false


I know Drupal adds some variables here (e.g. user session), but as you can see, my array has been added twice. One in the variables root, and another one inside the members variables (with the extra fields I do not want).

What am I doing wrong?

I thing the ideal situation is having the members variable inside the variables without the extra content (only once).

Do you have any idea?
This bit is the problem:

$variables['members'] = $variables;


When you declare named variables in your theme function they are passed in as named keys of the $variables array. So when you call your theme function:

// Note the array wrapping the passed variable and also the 'members' key of the array. This is required in Drupal 7.
print theme('team_members', array('members' =&gt; $members)); 


This is what you'll get in your preprocess function:

$members = $variables['members']; // This contains the original member array passed to the theme function as the named variable 'members'.


What you're doing at the moment is overwriting $variables['members'] with the $variables array itself, so all you're really doing is adding an extra array around the variables array.

Try putting the members that are passed into the preprocess function into a different variable:

$variables['custom_variable'] = do_something_to($variables['members']);


and outputting that one in your template file:

print $custom_variable;


I think that's what you're trying to do, have a look at hook_theme() for more information :)