Skip to content

Instantly share code, notes, and snippets.

@sun
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sun/180f508862b30b6cb973 to your computer and use it in GitHub Desktop.
Save sun/180f508862b30b6cb973 to your computer and use it in GitHub Desktop.
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
Copy link
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