php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #3079 Unset() leaves holes in arrays
Submitted: 2000-01-01 11:44 UTC Modified: 2002-10-01 11:05 UTC
From: tobias at dnet dot it Assigned:
Status: Wont fix Package: Misbehaving function
PHP Version: 3.0.13 OS: Suse Linux 6.1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tobias at dnet dot it
New email:
PHP Version: OS:

 

 [2000-01-01 11:44 UTC] tobias at dnet dot it
Unset(), when applied to array elements, leaves holes in the array.

Take this code:
$array = array("a");
unset($array[0]);
$array[] = "d";
var_dump($array);

This will produce the following output with PHP 3.0.12 and 3.0.13:
array(2) {
  int(1)
  string(1) "d"
}

a) It would make more sense if the index would be 0.
b) var_dump() sees the array as containing two elements. Count() works fine, though. PHP 4.x's var_dump() shows correctly array(1).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-01 11:05 UTC] hholzgra@php.net
We are sorry, but can not support PHP 3 related problems
anymore.  Momentum is gathering for PHP 5, and we think
supporting PHP 3 will lead to a waste of resources which
we want to put into getting PHP 5 ready. Ofcourse PHP 4
will continue to be supported for the forseeable future.

for a) unset doesn't renumber, remember that all php
       arrays are actually hashes
    b) well, see message above
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC