|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79927 Generator doesn't throw exception after multiple yield from iterable
Submitted: 2020-08-03 21:14 UTC Modified: 2020-10-11 00:08 UTC
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: roxblnfk at yandex dot com Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.4.8 OS: any
Private report: No CVE-ID: None
 [2020-08-03 21:14 UTC] roxblnfk at yandex dot com
A generator that yields values from an array does not throw an exception when calling the rewind method after multiple yields from same yield construction.

Can also be seen at

Test script:

$generator = (static function () {
    yield from [1,2,3];

echo $generator->current(); # 3

Expected result:
RuntimeException on line $generator->rewind();

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-08-11 13:49 UTC]
Automatic comment on behalf of
Log: Fixed bug #79927
 [2020-08-11 13:49 UTC]
-Status: Open +Status: Closed
 [2020-10-10 21:15 UTC] roxblnfk at ya dot ru
Do i understand correctly that this bug will not be fixed for php 7?
 [2020-10-11 00:08 UTC]
-Assigned To: +Assigned To: requinix
 [2020-10-11 00:08 UTC]
That's right. Because it would not be polite if code that already runs in 7.4 suddenly started throwing exceptions with the next release.
 [2020-10-11 00:08 UTC]
-Assigned To: requinix +Assigned To: nikic
 [2020-10-11 14:24 UTC] roxblnfk at yandex dot com
I think those who wrote the generator rewind code did it with the behavior described in the documentation.
I wrote the code too, expecting and considering that the generator would throw an exception. The incorrect behavior was found only during testing.
I, of course, do not insist, but think that it is worth releasing a fix for php7 and writing a warning in the patch note.

Now php7 does not work as it is written in the documentation regarding Generator::rewind()
 [2020-10-19 11:07 UTC] sam at rmcreative dot ru
I think it should be fixed in PHP 7 as well:

1. It contradicts documentation.
2. There's no way to work around it.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 13:01:29 2024 UTC