"global" keyword does not work from within drush script I have the following script:

&lt;?php 

$GLOBALS['foo1'] = "foobar1";
function g1() {
    echo "g1 " . $GLOBALS['foo1'] . "\n";
}

$foo2 = "foobar2";
function g2() {
    global $foo2;
    echo "g2 " . $foo2 . "\n";
}

g1();
g2();


Running it on the browser gives me:

g1 foobar1
g2 foobar2


Running it via drush scr example.php gives me:

g1 foobar1
g2


Any idea why the global keyword doesn't work when I run the script via drush?

I run this on a D7 site with PHP 5.3.5.
To solve it I had to add global $foo; before declaring $foo.

I suppose it relates to this: http://php.net/manual/en/language.variables.scope.php#98811