note 21633 added to language.variables.scope

From: Date: Tue, 21 May 2002 20:02:42 +0000
Subject: note 21633 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-30861@lists.php.net to get a copy of this message
comment on april 9 regarding: function foo () { global $testvar; $localvar = new Object (); $testvar = &$localvar; } The reason this doesn't work is that when you use & to assign to $testvar, it reassigns $testvar to point at what $localvar points at. $testvar = $localvar should work as well as $GLOBALS['testvar'] = &$localvar, although instance data will be copied and any references to parent classes will be broken. I hate that :). In other words, the declaration "global $testvar;" is telling php "make $testvar point at the same location as $GLOBALS['testvar']" but "$testvar = &$localvar" tells php "make $testvar point at the same location as $localvar"!!! -- http://www.php.net/manual/en/language.variables.scope.php http://master.php.net/manage/user-notes.php?action=edit+21633 http://master.php.net/manage/user-notes.php?action=delete+21633 http://master.php.net/manage/user-notes.php?action=reject+21633

« previous php.notes (#30861) next »