Bug #55157 [Asn]: ArrayIterator::offsetUnset(); does not work correctly
| From: | joey@php.net | Date: | Thu, 07 Jul 2011 11:17:12 +0000 |
| Subject: | Bug #55157 [Asn]: ArrayIterator::offsetUnset(); does not work correctly | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-161687@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=55157&edit=1
ID: 55157
Updated by: joey@php.net
Reported by: olav at fwt dot no
Summary: ArrayIterator::offsetUnset(); does not work
correctly
Status: Assigned
Type: Bug
Package: SPL related
Operating System: openSUSE 11.4/Debian 5
PHP Version: Irrelevant
Assigned To: colder
Block user comment: N
Private report: N
New Comment:
Just to narrow the scope of the bug a bit:
$a = range( 0,9 );
$b = new ArrayIterator( $a );
foreach($b as $k=>$v) {
$b->offsetUnset($k);
}
var_dump($b->getArrayCopy()); // why is 1 still around?
Previous Comments:
------------------------------------------------------------------------
[2011-07-07 06:52:24] olav at fwt dot no
Description:
------------
ArrayIterator always skips the second element in the array when calling
offsetUnset(); on it while looping through.
Using the key from iterator and unsetting in the actual ArrayObject works as
expected.
Running php 5.3.5 on openSUSE 11.4
Replicated same bug on Debian 5 running PHP 5.2.6-1+lenny9.
php5 is installed as binary on both systems, SPL is builtin package.
Test script:
---------------
<?php
// Create a array range from 0 to 9
$a = new ArrayObject( range( 0,9 ) );
$b = new ArrayIterator( $a );
for ( $b->rewind(); $b->valid(); $b->next() )
{
echo "#{$b->current()} - \r\n";
$b->offsetUnset( $b->key() );
}
?>
Expected result:
----------------
Expected a list of from 0 to 9 echoed out.
Actual result:
--------------
Lists out 0 and then 2-9 leaving index 1 untouched in the original ArrayObject.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55157&edit=1