Bug #11466 Updated: it works ambiguously to unset the global variable in function

From: Date: Wed, 13 Jun 2001 17:32:23 +0000
Subject: Bug #11466 Updated: it works ambiguously to unset the global variable in function
Groups: php.dev 
Request: Send a blank email to php-dev+get-57018@lists.php.net to get a copy of this message
ID: 11466 Updated by: sniper Reported By: vanity@neowiz.com Old-Status: Open Status: Bogus Bug Type: Variables related Operating system: PHP Version: 4.0.4pl1 Assigned To: Comments: Yes, this is how it works, not a bug. Previous Comments: --------------------------------------------------------------------------- [2001-06-13 11:14:10] vanity@neowiz.com These two sources are the same except the last line of the second one. The former represents that it doesn't work to unset the global variable, the latter that it only works when unset throught the $GLOBALS variable. [SRC 1: unset doesn't work] ============================================================ <?php function unset_variable ($name, $flag) { global $$name; global $GLOBALS; if ($flag & 1) { echo " - <font color=magenta>unset $$name</font><br>n"; unset($$name); } if ($flag & 2) { echo " - <font color=magenta>unset $GLOBALS["$name"]</font><br>n"; unset($GLOBALS[$name]); } } function disp_variable ($name) { global $$name; global $GLOBALS; printf(" - $%s : %s<BR>n", $name, isset($$name) ? "<font color=green>".$$name."</font>" : "<font color=red>(unset)</font>"); printf(" - $GLOBALS[%s] : %s<BR>n", $name, isset($GLOBALS[$name]) ? "<font color=green>".$GLOBALS[$name]."</font>" : "<font color=red>(unset)</font>"); } for ($i=0; $i < 4; $i++) { $name = "var$i"; $$name = "VALUE_$i"; $step = $i; $flag = $i; printf("<font color=blue>STEP (%s)</font><BR>n", $step); disp_variable ($name); unset_variable ($name, $flag); disp_variable ($name); printf("<BR>n"); } ?> ============================================================ [SRC 2: unset works only throught the $GLOBALS variable] ============================================================ <?php function unset_variable ($name, $flag) { global $$name; global $GLOBALS; if ($flag & 1) { echo " - <font color=magenta>unset $$name</font><br>n"; unset($$name); } if ($flag & 2) { echo " - <font color=magenta>unset $GLOBALS["$name"]</font><br>n"; unset($GLOBALS[$name]); } } function disp_variable ($name) { global $$name; global $GLOBALS; printf(" - $%s : %s<BR>n", $name, isset($$name) ? "<font color=green>".$$name."</font>" : "<font color=red>(unset)</font>"); printf(" - $GLOBALS[%s] : %s<BR>n", $name, isset($GLOBALS[$name]) ? "<font color=green>".$GLOBALS[$name]."</font>" : "<font color=red>(unset)</font>"); } for ($i=0; $i < 4; $i++) { $name = "var$i"; $$name = "VALUE_$i"; $step = $i; $flag = $i; printf("<font color=blue>STEP (%s)</font><BR>n", $step); disp_variable ($name); unset_variable ($name, $flag); disp_variable ($name); printf("<BR>n"); } $GLOBALS[anything]; ?> ============================================================ --------------------------------------------------------------------------- ATTENTION! Do NOT reply to this email! To reply, use the web interface found at http://bugs.php.net/?id=11466&edit=2

« previous php.dev (#57018) next »