Community & Support

php global variables in drupal

Hello,

I have a question (hopefully easy one) - how do I access a php global variable inside a function in Drupal?
For example, following code prints "Hello World", but why in Drupal it doesn't work?

<?php

    $test
= "Hello World";
   
    function
printVar(){
        global
$test;
        echo
$test;
    }
   
   
printVar();
?>

Please help,
Thank you

Comments

that's not a drupal prob :P

try this

global $test;
$test = "hello world";

function printVar(){
  //print $GLOBALS['test'];
  global $test;
  echo $test;
}
printVar();

that works! Thank you

that works! Thank you

nobody click here