|
-
January 17th, 2011, 04:02 PM
#1
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"); ?> ...
-
January 17th, 2011, 07:07 PM
#2
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.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
January 18th, 2011, 06:37 AM
#3
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.
Last edited by MasterDucky; January 18th, 2011 at 10:19 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|