Skip to content

Instantly share code, notes, and snippets.

@sun sun/bug.php
Last active Aug 29, 2015

Embed
What would you like to do?
SplDoublyLinkedList::IT_MODE_LIFO unsets wrong key
<?php
$list = new SplDoublyLinkedList();
// Comment this out to make it behave.
$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO);
$list->push('one');
$list->push('two');
foreach ($list as $key => $value) {
if ($value === 'one') {
unset($list[$key]);
}
}
// Also note that 'two' gets re-keyed to 0 (but that seems to be expected behavior).
$expected = array('two');
echo "-- Actual result:\n", var_dump($list), "\n";
echo "-- Expected result:\n", var_dump($expected), "\n";
$ php bug.php
-- Actual result:
class SplDoublyLinkedList#1 (2) {
private $flags =>
int(2)
private $dllist =>
array(1) {
[0] =>
string(3) "one"
}
}
-- Expected result:
array(1) {
[0] =>
string(3) "two"
}
@sun

This comment has been minimized.

Copy link
Owner Author

sun commented Jul 30, 2014

Related, but different: https://bugs.php.net/bug.php?id=63154

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.