Re: questions about $_SERVER

From: Date: Tue, 13 Mar 2012 16:05:48 +0000
Subject: Re: questions about $_SERVER
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-317007@lists.php.net to get a copy of this message
On Tue, Mar 13, 2012 at 4:59 PM, Tedd Sperling <tedd.sperling@gmail.com> wrote: > On Mar 12, 2012, at 7:12 PM, Tim Streater wrote: >> <?php >> >> function yes ($a) >>     { >>     global $x; >>     if  ($a)  $x = "yes\n"; >>     } >> >> first (true); >> >> echo $x; >> >> ?> >> >> >> but I haven't looked into $GLOBALS enough to know whether using them instead would >> have saved my bacon. > > I'm not sure what would have saved bacon in the above case. I don't see how your > example would work. I think it contained a typo. > > In what I think you were trying to demonstrate, I would just pass $x by reference (&$x) -- > or -- return $x by value. I would not have used a global, > > In any event, I seldom use globals anyway. This was more an academic discussion. > > Cheers, > > tedd > I would indeed mark it as bad practice using them. I only use them for debugging purposes. When developing something, you might end up needing some global variable temporary, and you don't want to pass it through a few dozen functions before reaching the one where you need it. - Matijn

« previous php.general (#317007) next »