note 14251 added to language.variables.scope.php

From: Date: Tue, 24 Jul 2001 04:28:10 +0000
Subject: note 14251 added to language.variables.scope.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-15751@lists.php.net to get a copy of this message
WARNING! If you create a local variable in a function and then within that function assign it to a global variable by reference the object will be destroyed when the function exits and the global var will contain NOTHING! This main sound obvious but it can be quite tricky you have a large script (like a phpgtk-based gui app ;-) ). example: function foo () { global $testvar; $localvar = new Object (); $testvar = &$localvar; } foo (); print_r ($testvar); // produces NOTHING!!!! hope this helps someone before they lose all their hair http://www.php.net/manual/en/language.variables.scope.php

« previous php.notes (#15751) next »