Re: Global variable unset in function
| From: | Joey | Date: | Thu, 01 Jun 2000 17:12:48 +0000 |
| Subject: | Re: Global variable unset in function | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-19996@lists.php.net to get a copy of this message | ||
As was reported in the bug, use unset($GLOBALS["var"]).
Here's why:
function f()
{
global $t;
// bind local $t to global $t
unset($t);
// break global binding
$t = "anything";
// $t is on a local var, and will go out of scope at
// function end
}
$t = "something";
f();
print $t;
// We never changed the globally scoped copy of $t
// so we get "something"
--Joey Smith
Please forgive the long sig:
*** Notice To Bulk Emailers: Attention! Pursuant to US Code, Title 47,
Chapter 5, Subchapter II, 227, any & all unsolicited commercial e-mail
sent to this address is subject to a download and archival fee in the
amount of the $1500 US and copies will be forwarded to domain
administrators. Emailing denotes acceptance of said terms!
On Wed, 31 May 2000, John Hamlik wrote:
> Has anyone seen a work around to this Bug 3647. We have the problem as well
> where we can't unset a global within a function. It is removed from the
> local scope but not the global.
>
> Thanks,
> John
>
> --
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net
> For additional commands, e-mail: php-dev-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>