From: CHU Zhaowei Date: Sun, 10 Dec 2017 18:22:55 +0000 (+0800) Subject: fix #74519 strange behavior of AppendIterator X-Git-Tag: php-7.1.15RC1~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=495508ecebb042bf252510fc508ac3745b588bb9;p=php fix #74519 strange behavior of AppendIterator --- 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-- +append($events); + +$events->next(); + +while($iterator->valid()) { + echo $iterator->current(), "\n"; + $iterator->next(); +} +?> +===DONE=== +--EXPECT-- +2 +3 +4 +5 +===DONE===