-
Globals help
I tried to read about global variables on tutorials but they only talking about globals in user created functions.
So what i'd like to know is if i declare a variable in the main index file will it be global for the files that i include after?
And is it the same for arrays?
PHP Code:
...
<?php
$realpath = "G:\\hello.txt";
$titles = array();
include("file1.php");
include("file2.php");
?>
...
-
Re: Globals help
You could have tested it out just as easily yourself.
In short...no. Variables from included files will be available in the PHP file calling the included files after the line in which the file is included. But, variables in the main file are not recognized within the included files.
-
Re: Globals help
I did test it before asking and was confused because i didnt get any error but still i couldnt change the
values of the variable either.
Now ive declared them in the included files like
PHP Code:
$realpath = "G:\\hello.txt";
$GLOBALS["realpath"];
include("switch.php");
but i still cant change them in switch.php (included in the main included file).
Edit: I did a small test and i realize that it works even without the $GLOBALS["realpath"]; so the problem must come from elsewhere.