From:             [EMAIL PROTECTED]
Operating system: RedHat 7.0
PHP version:      4.0.5
PHP Bug Type:     Scripting Engine problem
Bug description:  unset in function doesn't work on global arrays

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 Bug report at: http://bugs.php.net/?id=10810&edit=1



-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to