Reputation: 1
I have 2 files. Lets say :
first.php
$a = 'blah';
echo 'echo2='.$a;
function foo(){
global $a;
echo 'echo3='.$a;
return $a;
}
second.php
require_once(path/to/the/file/first.php);
echo 'echo='.$a;
$b = foo();
echo 'echo4='.$b;
running the second.php file I get the following output :
echo=blah
echo2=blah
echo3=
echo4=
My question is "why I can't access variable $a in the function foo !
Upvotes: 0
Views: 944
Reputation: 10806
or use
$GLOBALS["Your_var_without_dollar_sign"];
http://php.net/manual/en/reserved.variables.globals.php
Upvotes: 1
Reputation: 163232
Change $global
to global
. That should fix it.
http://php.net/manual/en/language.variables.scope.php
Upvotes: 3