Bug #10810 Updated: unset in function doesn't work on global arrays

From: Date: Fri, 11 May 2001 09:55:58 +0000
Subject: Bug #10810 Updated: unset in function doesn't work on global arrays
Groups: php.dev 
Request: Send a blank email to php-dev+get-54855@lists.php.net to get a copy of this message
ID: 10810 Updated by: derick Reported By: Martin.Sander@touch-screen.de Old-Status: Open Status: Bogus Bug Type: Scripting Engine problem Operating system: PHP Version: 4.0.5 Assigned To: Comments: Not a bug. The unset ($ar) in the unset all function removes the reference to the global variabele. Use unset($GLOBALS["ar"]) if you want this to work. Derick Previous Comments: --------------------------------------------------------------------------- [2001-05-11 05:53:42] Martin.Sander@touch-screen.de unset in function doesn't work on global arrays example: <?php { function ListIt() { global $ar; if (is_array($ar)) { foreach($ar as $k => $v) { echo "ar[$k] = $v <br>n"; } } else { echo "empty/nonarray <br>n"; } echo "<br>n"; } function UnsetOne($i) { global $ar; unset($ar[$i]); } function UnsetAll() { global $ar; //echo "t1s: <br>n"; ListIt(); echo ":t1e <br>n"; unset($ar); //echo "t2s: <br>n"; ListIt(); echo ":t2e <br>n"; } echo "init: <br>n"; $ar = array(); $ar[1] = "a"; $ar[2] = "b"; $ar[3] = "c"; $ar[4] = "d"; ListIt(); echo "unset 3: <br>n"; UnsetOne(3); ListIt(); echo "unset all (global array in function): <br>n"; UnsetAll(); ListIt(); echo "unset all (top level): <br>n"; unset($ar); ListIt(); } ?> --------------------------------------------------------------------------- ATTENTION! Do NOT reply to this email! To reply, use the web interface found at http://bugs.php.net/?id=10810&edit=2

« previous php.dev (#54855) next »