Global Variables

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!

Moderator: General Moderators

Post Reply
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

Global Variables

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply