Bug #67821 [Opn->Nab]: Generator can be rewound

From: Date: Mon, 11 Aug 2014 10:51:47 +0000
Subject: Bug #67821 [Opn->Nab]: Generator can be rewound
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187071@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67821&edit=1 ID: 67821 Updated by: thekid@php.net Reported by: thekid@php.net Summary: Generator can be rewound -Status: Open +Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: Any PHP Version: 5.5.15 Block user comment: N Private report: N New Comment: Hrm, I just see that Zend/tests/generators/generator_rewind.phpt states: "A generator can only be rewinded before or at the first yield" (see also https://wiki.php.net/rfc/generators#rewinding_a_generator) Again, this does seem inconsistent with the statement "generators will not support rewinding". Previous Comments: ------------------------------------------------------------------------ [2014-08-11 10:34:15] thekid@php.net 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 this bug report at https://bugs.php.net/bug.php?id=67821&edit=1

« previous php.bugs (#187071) next »