note 22987 added to language.variables.scope
| From: | stlawson@php.net | Date: | Sat, 06 Jul 2002 00:22:16 +0000 |
| Subject: | note 22987 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-32656@lists.php.net to get a copy of this message | ||
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 ;)
--
http://www.php.net/manual/en/language.variables.scope.php
http://master.php.net/manage/user-notes.php?action=edit+22987
http://master.php.net/manage/user-notes.php?action=delete+22987
http://master.php.net/manage/user-notes.php?action=reject+22987