summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierrick Charron <pierrick@php.net>2011-06-28 11:09:06 +0000
committerPierrick Charron <pierrick@php.net>2011-06-28 11:09:06 +0000
commit1b416caeb181b98cb50ceb570bb84717d0bacc58 (patch)
tree9e64c477fbb264e8150fbb0395defaaad593c491
parent0c2ee427d762035bba1f34743b3e5959a858e995 (diff)
downloadphp-git-1b416caeb181b98cb50ceb570bb84717d0bacc58.tar.gz
Fixed bug #54971 (Wrong result when using iterator_to_array with use_keys on true)
-rw-r--r--NEWS3
-rwxr-xr-xext/spl/spl_iterators.c2
-rw-r--r--ext/spl/tests/bug54971.phpt45
3 files changed, 50 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 16f0a10046..78f2582bbb 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,9 @@ PHP NEWS
- PDO ODBC driver:
. Fixed data type usage in 64bit. (leocsilva at gmail dot com)
+- SPL extension:
+ . Fixed bug #54971 (Wrong result when using iterator_to_array with use_keys
+ on true). (Pierrick)
16 Jun 2011, PHP 5.3.7 RC1
- Upgraded bundled SQLite to version 3.7.6.3. (Scott)
diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c
index 944997c731..1b911b591d 100755
--- a/ext/spl/spl_iterators.c
+++ b/ext/spl/spl_iterators.c
@@ -3306,6 +3306,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)) {
@@ -3320,6 +3321,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--
+<?php
+
+$source = <<<XML
+<root>
+<node>val1</node>
+<node>val2</node>
+</root>
+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
+ (
+ )
+
+)