com php-src: fix bug #75173 incorrect behavior of AppendIterator::append in foreach loop: NEWS ext/spl/spl_iterators.c ext/spl/tests/ bug75173.phpt
| From: | Joe Watkins | Date: | Tue, 12 Sep 2017 06:05:58 +0000 |
| Subject: | com php-src: fix bug #75173 incorrect behavior of AppendIterator::append in foreach loop: NEWS ext/spl/spl_iterators.c ext/spl/tests/ bug75173.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-99367@lists.php.net to get a copy of this message | ||
Commit: 3e11b7fc217ee3ce7a3a2833a062d73537cf6bcc
Author: jhdxr <jhdxr@php.net> Mon, 11 Sep 2017 02:11:58 +0800
Committer: Joe Watkins <krakjoe@php.net> Tue, 12 Sep 2017 07:05:58 +0100
Parents: 9aa6898b9be78bb1e138488c3204bb745a31aca7
Branches: PHP-7.0 PHP-7.1 PHP-7.2 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3e11b7fc217ee3ce7a3a2833a062d73537cf6bcc
Log:
fix bug #75173 incorrect behavior of AppendIterator::append in foreach loop
Bugs:
https://bugs.php.net/75173
Changed paths:
M NEWS
M ext/spl/spl_iterators.c
A ext/spl/tests/bug75173.phpt
Diff:
diff --git a/NEWS b/NEWS
index a866e5c..bed20b3 100644
--- a/NEWS
+++ b/NEWS
@@ -33,6 +33,10 @@ PHP NEWS
. Fixed bug #74631 (PDO_PCO with PHP-FPM: OCI environment initialized
before PHP-FPM sets it up). (Ingmar Runge)
+- SPL:
+ . Fixed bug #75173 (incorrect behavior of AppendIterator::append in foreach loop).
+ (jhdxr)
+
- Standard:
. Fixed bug #75097 (gethostname fails if your host name is 64 chars long). (Andrea)
diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c
index fafa9dc..e32f1e8 100644
--- a/ext/spl/spl_iterators.c
+++ b/ext/spl/spl_iterators.c
@@ -3384,7 +3384,7 @@ SPL_METHOD(AppendIterator, append)
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "O", &it,
zend_ce_iterator) == FAILURE) {
return;
}
- if (intern->u.append.iterator->funcs->valid(intern->u.append.iterator) == SUCCESS) {
+ if (intern->u.append.iterator->funcs->valid(intern->u.append.iterator) == SUCCESS
&& spl_dual_it_valid(intern) != SUCCESS) {
spl_array_iterator_append(&intern->u.append.zarrayit, it);
intern->u.append.iterator->funcs->move_forward(intern->u.append.iterator);
}else{
diff --git a/ext/spl/tests/bug75173.phpt b/ext/spl/tests/bug75173.phpt
new file mode 100644
index 0000000..a2cc909
--- /dev/null
+++ b/ext/spl/tests/bug75173.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Bug #75173 incorrect behavior of AppendIterator::append in foreach loop
+--FILE--
+<?php
+
+$it = new \AppendIterator();
+$it->append(new ArrayIterator(['foo']));
+
+foreach ($it as $item) {
+ var_dump($item);
+
+ if ('foo' === $item) {
+ $it->append(new ArrayIterator(['bar']));
+ }
+}
+--EXPECT--
+string(3) "foo"
+string(3) "bar"