How to pass variables between theme functions I often use functions that contain variables in the following files:


Template.php 
Custom Panels Style Plugins 
node.tpl.php files 
field.tpl.php files 
views.tpl.php files


I often needed to pass variables between these functions. 

At the moment, I do this by declaring my variable as a global Using PHP's global command. However, I have read that is not best practice. Is there a better way?

I know that Drupal has variable_set() and  variable_get(). However, apparently these have similar problems to using Globals for lots of little variables.
I am newish to Drupal, but will give this a shot (I'm sure someone will tell me if I am wrong). 

You can set variables that exist in different contexts by using the template.php file of your theme by adding stuff to the $variables array with preprocessor functions. So you could maybe add your variables to the YOURTHEME_preprocess_html() function, which should make them available everywhere. 

function YOURTHEME_preprocess_html(&amp;$variables, $hook) {
  $variables['sample_variable'] = t('Lorem ipsum.');
}