Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ PHP NEWS
- Core:
. Fixed bug GH-15375 (Nested "yield from" skips items after a valid() or
next() call on the inner generator). (iliaal)
. Fixed bug GH-23301 (Nested "yield from" yields a value twice when the
middle generator ends with "yield from []"). (Lazizbek Ergashev)

- Opcache:
. Fixed opcache.protect_memory race under ZTS. (realFlowControl)
Expand Down
29 changes: 29 additions & 0 deletions Zend/tests/generators/gh23301.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
GH-23301 (Nested "yield from" yields a value twice when the middle generator ends with "yield from []")
--FILE--
<?php

function inner() {
yield "B";
}

function middle() {
yield "A";
yield from inner();
yield "C";
yield from [];
}

function outer() {
yield from middle();
}

foreach (outer() as $value) {
echo $value, "\n";
}

?>
--EXPECT--
A
B
C
2 changes: 1 addition & 1 deletion Zend/zend_generators.c
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */

/* yield from was used, try another resume. */
if (UNEXPECTED(generator->execute_data && generator->execute_data->opline->opcode == ZEND_YIELD_FROM)) {
delegator = generator;
delegator = generator->node.parent ? generator : orig_generator;
generator = zend_generator_get_current(orig_generator);
goto try_again;
}
Expand Down
Loading