php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1971 Problem with unsetting global-variables
Submitted: 1999-08-05 10:45 UTC Modified: 1999-08-07 13:11 UTC
From: jeress at iname dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0 Beta 1 OS: Linux (Debian potato), glibc2.1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
23 - 11 = ?
Subscribe to this entry?

 
 [1999-08-05 10:45 UTC] jeress at iname dot com
The following returns 2 under PHP3 and 1 under PHP4:
----
<html>
<body>
<?php
$tv = 1;

function test1()
{
global $tv; unset($tv); $tv = 2;
}

function test2()
{
global $tv; echo("should be 2: $tv");
}

test1();
test2();
?>
</body>
</html>
---
I don't think this is a compile/module problem (compiled with mysql, nothing else that really matters).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-08-07 13:11 UTC] zeev at cvs dot php dot net
This is an undocumented incompatiblity to an undocumented behavior.

in PHP 4.0 - with the notion of references - the behavior of
unset() is extremely clear - only the symbol you unset() is unset.
In this case, $tv is a local variable that points to the global
variable with the same name - so unsetting it only unsets the
local $tv.  If you want to unset the actual global $tv, you should
use unset($GLOBALS["tv"])

 [2021-03-04 22:29 UTC] armcewen at shaw dot ca
So, would repeating the global statement, before re-assigning to the variable change this behaviour?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 07:01:27 2024 UTC