Re: variable scope

From: Date: Tue, 12 Mar 2002 22:44:23 +0000
Subject: Re: variable scope
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-88252@lists.php.net to get a copy of this message
On Tue, 2002-03-12 at 14:38, David Johansen wrote: > I have a little chunk of code that checks to see if a variable exists and if > not then it sets it. It goes like this: > > if (empty($page)) > { > $page = "login"; > } > > I then end that part of the php script after doing what I need to. Then I > start up again on the same html page and I assumed that $page had a value > assigned to it because of the above code, but it appears that it doesn't. Is > this supposed to happen or is something weird happening. I added that little > bit of code to the second chunk of code and it fixed the problem. Is that > the "right" way to do it? Is that variable only available in the <?php ?> > that it's declared in? Thanks, > Dave Shouldn't be. A variable is valid from the point it's declared until it's unset(), or goes out of scope (the function within which it was declared ends), or the script ends. Can you provide a short script which exhibits this behaviour? -- Torben Wilson <torben@php.net> http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506

« previous php.general (#88252) next »