Bug #78434 [Ver]: Generator yields no items after valid() call

From: Date: Fri, 03 Apr 2020 10:10:11 +0000
Subject: Bug #78434 [Ver]: Generator yields no items after valid() call
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226419@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78434&edit=1 ID: 78434 Updated by: nikic@php.net Reported by: enumag at gmail dot com Summary: Generator yields no items after valid() call Status: Verified Type: Bug Package: *General Issues Operating System: irrelevant PHP Version: 7.3.11 Block user comment: N Private report: N New Comment: Candidate patch at https://github.com/php/php-src/pull/5344. Very much not sure this is right. Previous Comments: ------------------------------------------------------------------------ [2020-04-02 15:03:41] nikic@php.net It looks like the difference in behavior is because the first yield from runs with DO_INIT flag set, which prevents the initial advance. ------------------------------------------------------------------------ [2020-04-02 09:48:37] enumag at gmail dot com Bump. Just ran into this again, it is really bothering me that I can't rely on Generators to work correctly. Can you please fix this? ------------------------------------------------------------------------ [2019-08-23 15:53:19] nikic@php.net Sorry, I missed the different behavior for the two yield froms... something is definitely broken here. ------------------------------------------------------------------------ [2019-08-21 13:28:35] enumag at gmail dot com As far as I know calling Generator::rewind() is alright until next() is called for the first time. Which means that your argument whether or not should yield from call rewind() is not relevant here - the result would be the same regardless. ------------------------------------------------------------------------ [2019-08-21 13:24:38] enumag at gmail dot com > To make this more obvious, replace valid() with current() -- should the yield from repeat the > value you already fetched? Of course it should. I didn't call next() so the first value was not yet "consumed". Also as you can see in the example the behaviour is inconsistent between the first and second yield from. That's definitely not correct. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=78434 -- Edit this bug report at https://bugs.php.net/bug.php?id=78434&edit=1

« previous php.bugs (#226419) next »