GLOBAL / PUBLIC 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
UKSouthernLad
Forum Newbie
Posts: 5
Joined: Sun Jan 04, 2009 6:12 am

GLOBAL / PUBLIC variables

Post by UKSouthernLad »

Hi

What's the best way to create a variable that is created OUTSIDE of Classes, but accessible from inside all Classes... I don't want to use Session Variables unless absolutely necessary.


Thnx
msurabbott
Forum Commoner
Posts: 33
Joined: Thu Jan 01, 2009 10:18 pm
Location: Chicago, IL, USA

Re: GLOBAL / PUBLIC variables

Post by msurabbott »

Global and Session variables are different really only in the manor they are accessed and created. If you want to avoid using $_SESSION you can use global.

Create the variable like so:

Code: Select all

global $var;
$var = "15"
Then whenever you want to access it just do:

Code: Select all

global $var;
echo $var;
Post Reply