I have the following code:


function check() {
  global $a;

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


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.


1 Answer 1


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.