Skip to content

Commit

Permalink
Fixed by decrementing the iterator index when unset is called inside …
Browse files Browse the repository at this point in the history
…DocumentArray and Collection.
  • Loading branch information
Marc Ghorayeb committed Oct 25, 2011
1 parent 0b1afc5 commit 394ae79
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions data/collection/DocumentArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function __isset($name) {
*/
public function __unset($name) {
unset($this->_data[$name]);
prev($this->_data);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/data/collection/DocumentArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testUnsetInForeach() {
}
}

$expected = array('Hello', 'Hello again!');
$expected = array(0 => 'Hello', 6 => 'Hello again!');
$this->assertIdentical($expected, $doc->data());
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/util/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public function testUnsetInForeach() {
}
}

$expected = array('Hello', 'Hello again!');
$expected = array(0 => 'Hello', 6 => 'Hello again!');
$results = $collection->to('array');
$this->assertIdentical($expected, $results);
}
Expand Down
1 change: 1 addition & 0 deletions util/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ public function offsetSet($offset, $value) {
*/
public function offsetUnset($offset) {
unset($this->_data[$offset]);
prev($this->_data);
}

/**
Expand Down

0 comments on commit 394ae79

Please sign in to comment.