Re: Global vars

From: Date: Sun, 02 Jun 2002 06:59:19 +0000
Subject: Re: Global vars
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-100297@lists.php.net to get a copy of this message
global $var; does nothing outside of a function. You do not need to use global for this. $foo = 'bar'; include 'something_that_uses_foo.inc'; http://www.php.net/manual/en/language.variables.scope.php regards, Philip Olson On Sun, 2 Jun 2002, Anzak Wolf wrote: > I have a question about global vars. Why is it that I have to declare a var > global if I'm using it across included files. For example the only why I > can get this var to work is by making it global. > > main.php > <?php > include loader.inc; > include builder.inc; > include render.inc; > ?> > > loader.inc > <?php > global $obj; > $obj = new Whiz_bang(); > ?> > > builder.inc > <?php > global $obj; > $obj->build_whizzer(); > ?> > > render.inc > <?php > render->html(); > ?> > > considering that if you took the could and just inserted the code form the > included files into the main you would not need to make the var global why > is that I need to when I cross files. I don't think I have read a good > reasoning for this anywhere. My goal is simple to use as few global vars as > possible which is why I ask. > > _________________________________________________________________ > Send and receive Hotmail on your mobile device: > http://mobile.msn.com > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#100297) next »