Page 1 of 1

GLOBAL / PUBLIC variables

Posted: Sun Jan 04, 2009 11:26 am
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

Re: GLOBAL / PUBLIC variables

Posted: Sun Jan 04, 2009 11:38 am
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;