Problems accessing variables with the global keyword - Joomla! Forum - community, help and support
hi,
i have problems accessing variables within function. variable defined in same file function is, when call function (happens in file) cant use variable.
file function.php
<?php
$var = "hello";
function test()
{
global $var;
var_dump($var);
}
?>
file caller.php
<?php
include "function.php";
test(); // prints null
?>
is me can't working?
i have problems accessing variables within function. variable defined in same file function is, when call function (happens in file) cant use variable.
file function.php
<?php
$var = "hello";
function test()
{
global $var;
var_dump($var);
}
?>
file caller.php
<?php
include "function.php";
test(); // prints null
?>
is me can't working?
your example works fine, producing following line:
code: select all
string(5) "hello"
Comments
Post a Comment