summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCHU Zhaowei <jhdxr@php.net>2017-12-11 02:22:55 +0800
committerJoe <krakjoe@php.net>2018-02-08 10:15:09 +0100
commit495508ecebb042bf252510fc508ac3745b588bb9 (patch)
tree54e73ca84387e41b4ed597c26451e9d2db94a159
parent1368aea352efc262d16ee9dc8e3d019908180b09 (diff)
downloadphp-git-495508ecebb042bf252510fc508ac3745b588bb9.tar.gz
fix #74519 strange behavior of AppendIterator
-rw-r--r--ext/spl/spl_iterators.c27
-rw-r--r--ext/spl/tests/bug74519.phpt23
2 files changed, 48 insertions, 2 deletions
diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c
index db6896965a..75550be175 100644
--- a/ext/spl/spl_iterators.c
+++ b/ext/spl/spl_iterators.c
@@ -1797,7 +1797,6 @@ SPL_METHOD(dual_it, key)
proto mixed ParentIterator::current()
proto mixed IteratorIterator::current()
proto mixed NoRewindIterator::current()
- proto mixed AppendIterator::current()
Get the current element value */
SPL_METHOD(dual_it, current)
{
@@ -1809,6 +1808,7 @@ SPL_METHOD(dual_it, current)
SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis());
+ spl_dual_it_fetch(intern, 1);
if (Z_TYPE(intern->current.data) != IS_UNDEF) {
zval *value = &intern->current.data;
@@ -3393,6 +3393,29 @@ SPL_METHOD(AppendIterator, append)
}
} /* }}} */
+/* {{{ proto mixed AppendIterator::current()
+ Get the current element value */
+SPL_METHOD(AppendIterator, current)
+{
+ spl_dual_it_object *intern;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis());
+
+ spl_dual_it_fetch(intern, 1);
+ if (Z_TYPE(intern->current.data) != IS_UNDEF) {
+ zval *value = &intern->current.data;
+
+ ZVAL_DEREF(value);
+ ZVAL_COPY(return_value, value);
+ } else {
+ RETURN_NULL();
+ }
+} /* }}} */
+
/* {{{ proto void AppendIterator::rewind()
Rewind to the first iterator and rewind the first iterator, too */
SPL_METHOD(AppendIterator, rewind)
@@ -3485,7 +3508,7 @@ static const zend_function_entry spl_funcs_AppendIterator[] = {
SPL_ME(AppendIterator, rewind, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
SPL_ME(AppendIterator, valid, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
SPL_ME(dual_it, key, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
- SPL_ME(dual_it, current, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
+ SPL_ME(AppendIterator, current, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
SPL_ME(AppendIterator, next, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
SPL_ME(dual_it, getInnerIterator, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
SPL_ME(AppendIterator, getIteratorIndex, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
diff --git a/ext/spl/tests/bug74519.phpt b/ext/spl/tests/bug74519.phpt
new file mode 100644
index 0000000000..92efb6378a
--- /dev/null
+++ b/ext/spl/tests/bug74519.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Bug #74519 strange behavior of AppendIterator
+--FILE--
+<?php
+
+$iterator = new \AppendIterator();
+$events = new \ArrayIterator([1,2,3,4,5]);
+$iterator->append($events);
+
+$events->next();
+
+while($iterator->valid()) {
+ echo $iterator->current(), "\n";
+ $iterator->next();
+}
+?>
+===DONE===
+--EXPECT--
+2
+3
+4
+5
+===DONE===