Bug #67821 [NEW]: Generator can be rewound
| From: | thekid@php.net | Date: | Mon, 11 Aug 2014 10:34:16 +0000 |
| Subject: | Bug #67821 [NEW]: Generator can be rewound | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-187070@lists.php.net to get a copy of this message | ||
From: thekid@php.net
Operating system: Any
PHP version: 5.5.15
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Generator can be rewound
Description:
------------
A generator can be rewound if and only if its first yielded value has
been fetched. As soon as we fetch the second (or any further) yielded
value and *then* try to rewind it we actually get the exception. This is
inconsistent.
Test script:
---------------
$f= function() { yield 1; yield 2; yield 3; };
$gen= $f();
foreach ($gen as $val) { var_dump($val); }
foreach ($gen as $val) { var_dump($val); } // Exception("Cannot rewind
a generator that was already run")
# Here's the bug:
foreach ($gen as $val) { var_dump($val); break; }
foreach ($gen as $val) { var_dump($val); } // No exception
Expected result:
----------------
int(1)
Exception("Cannot rewind a generator that was already run")
Actual result:
--------------
int(1)
int(1)
int(2)
int(3)
--
Edit bug report at https://bugs.php.net/bug.php?id=67821&edit=1
--