Last active
August 29, 2015 14:04
-
-
Save sun/180f508862b30b6cb973 to your computer and use it in GitHub Desktop.
SplDoublyLinkedList::IT_MODE_LIFO unsets wrong key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related, but different: https://bugs.php.net/bug.php?id=63154