From a81406380489e4604786f5137f95095f88027053 Mon Sep 17 00:00:00 2001 From: Pierrick Charron Date: Tue, 28 Jun 2011 11:09:06 +0000 Subject: [PATCH] Fixed bug #54971 (Wrong result when using iterator_to_array with use_keys on true) --- ext/spl/spl_iterators.c | 2 ++ ext/spl/tests/bug54971.phpt | 45 +++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 ext/spl/tests/bug54971.phpt diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index d8ee7c525f..e062486731 100755 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -3446,6 +3446,7 @@ PHPAPI int spl_iterator_apply(zval *obj, spl_iterator_apply_func_t apply_func, v goto done; } + iter->index = 0; if (iter->funcs->rewind) { iter->funcs->rewind(iter TSRMLS_CC); if (EG(exception)) { @@ -3460,6 +3461,7 @@ PHPAPI int spl_iterator_apply(zval *obj, spl_iterator_apply_func_t apply_func, v if (apply_func(iter, puser TSRMLS_CC) == ZEND_HASH_APPLY_STOP || EG(exception)) { goto done; } + iter->index++; iter->funcs->move_forward(iter TSRMLS_CC); if (EG(exception)) { goto done; diff --git a/ext/spl/tests/bug54971.phpt b/ext/spl/tests/bug54971.phpt new file mode 100644 index 0000000000..166613b434 --- /dev/null +++ b/ext/spl/tests/bug54971.phpt @@ -0,0 +1,45 @@ +--TEST-- +Bug #54971 (Wrong result when using iterator_to_array with use_keys on true) +--FILE-- + +val1 +val2 + +XML; + + +$doc = new DOMDocument(); +$doc->loadXML($source); + +$xpath = new DOMXPath($doc); +$items = $xpath->query('//node'); + +print_r(iterator_to_array($items, false)); +print_r(iterator_to_array($items, true)); +?> +--EXPECT-- +Array +( + [0] => DOMElement Object + ( + ) + + [1] => DOMElement Object + ( + ) + +) +Array +( + [0] => DOMElement Object + ( + ) + + [1] => DOMElement Object + ( + ) + +) -- 2.40.0