#10810 [Com]: unset in function doesn't work on global arrays
| From: | links-urine1462 at hotmail dot com | Date: | Tue, 20 Jul 2004 15:03:11 +0000 |
| Subject: | #10810 [Com]: unset in function doesn't work on global arrays | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-62867@lists.php.net to get a copy of this message | ||
ID: 10810
Comment by: links-urine1462 at hotmail dot com
Reported By: Martin dot Sander at touch-screen dot de
Status: Bogus
Bug Type: Scripting Engine problem
Operating System: RedHat 7.0
PHP Version: 4.0.5
New Comment:
<a href=http://t--fisting-urine-li.da.ru>links
urine</a>
Previous Comments:
------------------------------------------------------------------------
[2001-05-11 05:55:58] derick@php.net
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
------------------------------------------------------------------------
[2001-05-11 05:53:42] Martin dot Sander at touch-screen dot 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();
}
?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=10810&edit=1