note 21633 deleted from language.variables.scope by danbrown

From: Date: Mon, 18 May 2009 01:43:02 +0000
Subject: note 21633 deleted from language.variables.scope by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155586@lists.php.net to get a copy of this message
Note Submitter: cellog at users dot sourceforge dot net ---- 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"!!!

« previous php.notes (#155586) next »