Bug #79927 [Com]: Generator doesn't throw exception after multiple yield from iterable
Edit report at https://bugs.php.net/bug.php?id=79927&edit=1
ID: 79927
Comment by: sam at rmcreative dot ru
Reported by: roxblnfk at yandex dot com
Summary: Generator doesn't throw exception after multiple
yield from iterable
Status: Closed
Type: Bug
Package: Scripting Engine problem
Operating System: any
PHP Version: 7.4.8
Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
I think it should be fixed in PHP 7 as well:
1. It contradicts documentation.
2. There's no way to work around it.
Previous Comments:
------------------------------------------------------------------------
[2020-10-11 14:24:11] 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-11 00:08:29] 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-10 21:15:09] roxblnfk at ya dot ru
Do i understand correctly that this bug will not be fixed for php 7?
------------------------------------------------------------------------
[2020-08-11 13:49:53] 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-03 21:14:46] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79927&edit=1
Thread (6 messages)