Problems with a global variable I have the following code:

$a='1';

function check() {
  global $a;

  if ($a == '1') {
    return "1";
  }
  else {
    return "2";
  }

  var_dump(check());
}


When I run this code stand alone, its output is string(1) "1"; when I use the code inside page-front.tpl.php the output is string(1) "2.

Why?
When Drupal includes the template file, your declaration of $a = '1' is not in the global scope. You need to declare it as such:

global $a;
$a = '1';


Since you're diving into the realm of global variables though, I'd recommend using a more distinctive name, or figuring out how to avoid globals altogether.