Page 1 of 1

Global Variables

Posted: Sun Jan 30, 2005 10:45 pm
by SBro
Is this the correct way to setup a globals file? For stuff such as page titles, headers, footers, etc

Code: Select all

// globals.inc

$var1 = "text";
$var2 = "blah";

function reg_globals() {
global $var1, $var2;
}
I can then call a global like this:

Code: Select all

include_once "globals.inc";

echo 'Var1: '.$var1;
Is that the correct way of doing things or is there a better method? thankyou.

Posted: Sun Jan 30, 2005 10:49 pm
by feyd
that's a general way it can be done. Frankly, there are many ways, all of which have their merit. As long as it works for you and your project it's mostly okay.

Now, if it's for a larger released project, then you'd need to follow whatever coding guidelines they have in place, or create them if such rules do not exist.