Bug #76104 [NEW]: foreach over a generator with an intermit send() works unexpectedly

From: Date: Fri, 16 Mar 2018 06:44:14 +0000
Subject: Bug #76104 [NEW]: foreach over a generator with an intermit send() works unexpectedly
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-214378@lists.php.net to get a copy of this message
From: alexey at kopytko dot com Operating system: PHP version: 7.2.3 Package: Scripting Engine problem Bug Type: Bug Bug description:foreach over a generator with an intermit send() works unexpectedly Description: ------------ foreach calls next() on a generator, which for some reason triggers send(null) on the generator. All previous versions are also affected: https://3v4l.org/bfg64#v560 First reported here: https://stackoverflow.com/q/37817315 Test script: --------------- $generator = (function () { for ($i = 0; $i < 5; $i += 1) { $answer = (yield $i * 2); echo "received: $answer\n"; } })(); foreach ($generator as $x) { echo "sending $x\n"; $generator->send($x); } Expected result: ---------------- sending 0 received: 0 sending 2 received: 2 sending 4 received: 4 sending 6 received: 6 sending 8 received: 8 Actual result: -------------- sending 0 received: 0 received: sending 4 received: 4 received: sending 8 received: 8 -- Edit bug report at https://bugs.php.net/bug.php?id=76104&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76104&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76104&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76104&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=76104&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=76104&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=76104&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=76104&r=needscript Try newer version: https://bugs.php.net/fix.php?id=76104&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=76104&r=support Expected behavior: https://bugs.php.net/fix.php?id=76104&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=76104&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=76104&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=76104&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76104&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=76104&r=dst IIS Stability: https://bugs.php.net/fix.php?id=76104&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=76104&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=76104&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=76104&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=76104&r=mysqlcfg

« previous php.bugs (#214378) next »