Skip to content

Commit 50cb4fc

Browse files
committed
Merge branch 'master' of git.php.net:/php-src
* 'master' of git.php.net:/php-src: fix bug #75173 incorrect behavior of AppendIterator::append in foreach loop
2 parents 89dceb5 + cb62dbe commit 50cb4fc

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,7 @@ PHP NEWS
6868
- SPL:
6969
. Fixed bug #74977 (Appending AppendIterator leads to segfault).
7070
(Andrew Nester)
71+
. Fixed bug #75173 (incorrect behavior of AppendIterator::append in foreach loop).
72+
(jhdxr)
7173

7274
<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>

ext/spl/spl_iterators.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3374,7 +3374,7 @@ SPL_METHOD(AppendIterator, append)
33743374
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "O", &it, zend_ce_iterator) == FAILURE) {
33753375
return;
33763376
}
3377-
if (intern->u.append.iterator->funcs->valid(intern->u.append.iterator) == SUCCESS) {
3377+
if (intern->u.append.iterator->funcs->valid(intern->u.append.iterator) == SUCCESS && spl_dual_it_valid(intern) != SUCCESS) {
33783378
spl_array_iterator_append(&intern->u.append.zarrayit, it);
33793379
intern->u.append.iterator->funcs->move_forward(intern->u.append.iterator);
33803380
}else{

ext/spl/tests/bug75173.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug #75173 incorrect behavior of AppendIterator::append in foreach loop
3+
--FILE--
4+
<?php
5+
6+
$it = new \AppendIterator();
7+
$it->append(new ArrayIterator(['foo']));
8+
9+
foreach ($it as $item) {
10+
var_dump($item);
11+
12+
if ('foo' === $item) {
13+
$it->append(new ArrayIterator(['bar']));
14+
}
15+
}
16+
--EXPECT--
17+
string(3) "foo"
18+
string(3) "bar"

0 commit comments

Comments
 (0)