]> granicus.if.org Git - php/commitdiff
fix #74519 strange behavior of AppendIterator
authorCHU Zhaowei <jhdxr@php.net>
Sun, 10 Dec 2017 18:22:55 +0000 (02:22 +0800)
committerJoe <krakjoe@php.net>
Thu, 8 Feb 2018 09:15:09 +0000 (10:15 +0100)
ext/spl/spl_iterators.c
ext/spl/tests/bug74519.phpt [new file with mode: 0644]

index db6896965ad0c79b9e5536028a58bc3ee61f6c39..75550be175b3777fbba09318bf3b055ec6633651 100644 (file)
@@ -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 (file)
index 0000000..92efb63
--- /dev/null
@@ -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===