Possible bug in PHP4 using unset() on a global variable

From: Date: Wed, 16 Aug 2000 12:56:55 +0000
Subject: Possible bug in PHP4 using unset() on a global variable
Groups: php.general 
Request: Send a blank email to php-general+get-11981@lists.php.net to get a copy of this message
Hi, I've found what seems to be a bug in PHP 4.0.1pl2. When I upgraded from PHP3, my code appeared to be broken. I've isolated the problem and can't find anything mentioned about a change of behaviour in the PHP4 docs. Bug: When you call unset() on a global variable, the variable becomes local again. In PHP3, any global variable remained global regardless of any calls to unset(). A simple example is included below. The expected result is that the output is "Before the function<BR>Inside the function<BR>". On PHP3, you get the expected result. On PHP4, you get "Before the function" output twice. Is this a known issue? If not, can someone repro. it and figure out how to fix it? If this *is* supposed to happen, how do you unset a global variable? (other than using $GLOBALS[] everywhere). Thanks, Chris. <?php function global_bug() { global $a; unset($a); $a = "Inside the function<BR>"; } $a = "Before the function<BR>"; echo $a; global_bug(); echo $a; ?>

« previous php.general (#11981) next »