Skip to content

Fix GH-23301: nested "yield from" repeats a value after "yield from []" - #23302

Open
lazerg wants to merge 1 commit into
php:PHP-8.4from
lazerg:fix/issue-23301-yield-from-empty-array
Open

Fix GH-23301: nested "yield from" repeats a value after "yield from []"#23302
lazerg wants to merge 1 commit into
php:PHP-8.4from
lazerg:fix/issue-23301-yield-from-empty-array

Conversation

@lazerg

@lazerg lazerg commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

GH-15375's fix made the DO_INIT re-advance guard in zend_generator_resume() read the flag from the delegating generator rather than from orig_generator. That flag is set by zend_generator_yield_from() and only ever cleared on orig_generator, so on a middle generator it stays set for the rest of its life.

When such a middle generator then delegates to a non-generator iterable (yield from []), it still sits on a ZEND_YIELD_FROM opline, so it is picked as the delegator even though no new generator link was established, and its stale DO_INIT suppresses the resume. The value it yielded last is presented a second time. Twig hits this on every template, since doDisplay() always ends with yield from [];.

Only treat the generator as the delegator when it actually delegated to another generator (node.parent is set); otherwise keep orig_generator as before. The GH-15375 tests still pass.

Fixes GH-23301

@lazerg
lazerg force-pushed the fix/issue-23301-yield-from-empty-array branch from c2f8b57 to 622159a Compare August 15, 2026 21:40
@lazerg lazerg changed the title Fix GH-23301: nested "yield from" yields a value twice when the middle generator ends with "yield from []" Fix GH-23301: nested "yield from" repeats a value after "yield from []" Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant