Bug #1971 [Com]: Problem with unsetting global-variables

From: Date: Thu, 04 Mar 2021 22:29:01 +0000
Subject: Bug #1971 [Com]: Problem with unsetting global-variables
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232566@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=1971&edit=1 ID: 1971 Comment by: armcewen at shaw dot ca Reported by: jeress at iname dot com Summary: Problem with unsetting global-variables Status: Closed Type: Bug Package: Scripting Engine problem Operating System: Linux (Debian potato), glibc2.1 PHP Version: 4.0 Beta 1 Block user comment: N Private report: N New Comment: So, would repeating the global statement, before re-assigning to the variable change this behaviour? Previous Comments: ------------------------------------------------------------------------ [1999-08-07 13:11:17] 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"]) ------------------------------------------------------------------------ [1999-08-05 10:45:00] 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). ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=1971&edit=1

« previous php.bugs (#232566) next »