php.net |  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
Votes:2
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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: roxblnfk at yandex dot com
New email:
PHP Version: OS:

 

 [2020-08-03 21:14 UTC] roxblnfk at yandex dot com
Description:
------------
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 https://3v4l.org/NZ77U

Test script:
---------------
<?php

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

$generator->next();
$generator->next();
$generator->rewind();
echo $generator->current(); # 3

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

Actual result:
--------------
3

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-08-11 13:49 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e25aab64268adb4e233737c274b195e1662f7211
Log: Fixed bug #79927
 [2020-08-11 13:49 UTC] nikic@php.net
-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] requinix@php.net
-Assigned To: +Assigned To: requinix
 [2020-10-11 00:08 UTC] requinix@php.net
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] requinix@php.net
-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: Fri Mar 29 07:01:28 2024 UTC