summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/spl/spl_dllist.c4
-rw-r--r--ext/spl/tests/SplDoublyLinkedList_consistent_iterator_mode.phpt39
2 files changed, 41 insertions, 2 deletions
diff --git a/ext/spl/spl_dllist.c b/ext/spl/spl_dllist.c
index 7dbc3699d0..b11cfacc3c 100644
--- a/ext/spl/spl_dllist.c
+++ b/ext/spl/spl_dllist.c
@@ -964,7 +964,7 @@ static void spl_dllist_it_rewind(zend_object_iterator *iter) /* {{{ */
spl_dllist_object *object = Z_SPLDLLIST_P(&iter->data);
spl_ptr_llist *llist = object->llist;
- spl_dllist_it_helper_rewind(&iterator->traverse_pointer, &iterator->traverse_position, llist, object->flags);
+ spl_dllist_it_helper_rewind(&iterator->traverse_pointer, &iterator->traverse_position, llist, iterator->flags);
}
/* }}} */
@@ -1005,7 +1005,7 @@ static void spl_dllist_it_move_forward(zend_object_iterator *iter) /* {{{ */
zend_user_it_invalidate_current(iter);
- spl_dllist_it_helper_move_forward(&iterator->traverse_pointer, &iterator->traverse_position, object->llist, object->flags);
+ spl_dllist_it_helper_move_forward(&iterator->traverse_pointer, &iterator->traverse_position, object->llist, iterator->flags);
}
/* }}} */
diff --git a/ext/spl/tests/SplDoublyLinkedList_consistent_iterator_mode.phpt b/ext/spl/tests/SplDoublyLinkedList_consistent_iterator_mode.phpt
new file mode 100644
index 0000000000..fa901dda91
--- /dev/null
+++ b/ext/spl/tests/SplDoublyLinkedList_consistent_iterator_mode.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Iteration over SplDoublyLinkedList via 'foreach' does not change direction partway
+--FILE--
+<?php
+
+$list = new SplDoublyLinkedList();
+$list->push(1);
+$list->push(2);
+$list->push(3);
+
+/* SplDoublyLinkedList would previously check the iteration mode *each time*
+ it would advance to the next item in a 'foreach' loop
+ This meant that it could move forward, then backward, then forward if the
+ iteration mode was changed in the middle of a loop */
+
+$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
+foreach ($list as $item) {
+ $list->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO);
+ echo $item, "\n";
+}
+
+echo "***\n";
+
+$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO);
+foreach ($list as $item) {
+ $list->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
+ echo $item, "\n";
+}
+
+
+?>
+--EXPECT--
+1
+2
+3
+***
+3
+2
+1