PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I would like to make $ajaxsupport a global variable or at least make it available to files that include the file it's declared on. I've read this page but it's examples are backwards declaring a variable and then including another file? The examples on php.net seem only aimed to help those who pretty much know what they are doing already.
Parse error: parse error, unexpected '=', expecting ',' or ';' on line 43
So it's not setting it as a global. I'm pretty sure I'm not correctly setting this as a variable. What I've been reading is that I can set a global manually (even though register_globals is off) if I set a global inside of a function. Is this true? If so what am I doing wrong?
I added the echo and of course it's not going to do anything as I have some sort of error.
<?php
// sometimes this line below is also needed. Don't know why.
// Most times I need this line when including/requiring files.
//global $test;
function something() {
global $test;
$test = TRUE;
}
something();
var_dump($test);
?>
Even though I fixed my code by adding the beginning parenthesis for the original post I don't understand why it didn't work earlier?
So let me make this really simple: if I only declare a variable in a file (even without it being declared inside of a function) I can use it as a global variable so long as I don't do anything with that variable after it's initial declaration on the page it was declared?
It works perfectly now (both locally and on a couple live servers) though it would have been nice if it had worked the first time around.