mirror of
https://github.com/php/php-src.git
synced 2024-12-05 07:46:06 +08:00
Fixed bug #54971 (Wrong result when using iterator_to_array with use_keys on true)
This commit is contained in:
parent
f99938c6ee
commit
a814063804
@ -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;
|
||||
|
45
ext/spl/tests/bug54971.phpt
Normal file
45
ext/spl/tests/bug54971.phpt
Normal file
@ -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
|
||||
(
|
||||
)
|
||||
|
||||
)
|
Loading…
Reference in New Issue
Block a user