note 22987 deleted from language.variables.scope by danbrown

From: Date: Mon, 18 May 2009 01:42:45 +0000
Subject: note 22987 deleted from language.variables.scope by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155582@lists.php.net to get a copy of this message
Note Submitter: stlawson AT sbcglobal DOT net ---- aslak is right! Check this out: $t1 = "outie"; function foo1() { global $t1; $t1 = 'innie' ; echo ('in foo1() $t1 is an ' . $t1) ; } echo ('before foo1() $t1 is an ' . $t1) ; foo1() ; echo ('after foo1() $t1 is an ' . $t1) ; // is identical to?: $t2 = "outie"; function foo2() { $t2 = &$GLOBALS['t2']; $t2 = 'innie' ; echo ('in foo2() $t2 is an ' . $t2) ; } echo ('before foo2() $t2 is an ' . $t2) ; foo2() ; echo ('after foo2() $t2 is an ' . $t2) ; Output: before foo1() $t1 is an outie in foo1() $t1 is an innie after foo1() $t1 is an innie before foo2() $t2 is an outie in foo2() $t2 is an innie after foo2() $t2 is an innie Also I cleaned up aslak's code a bit ;)

« previous php.notes (#155582) next »