[php-src] Issue #9902: Generator/yield + send = missed items

From: Date: Tue, 08 Nov 2022 10:42:26 +0000
Subject: [php-src] Issue #9902: Generator/yield + send = missed items
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-242764@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/9902 Author: LastDragon-ru ### Description Hello. This behaviour is mentioned on https://www.php.net/manual/en/generator.send.php#126068, but it looks very weird and makes send() useless :( Live: https://3v4l.org/qUmrk The following code: ```php <?php $factory = static function (): Generator { foreach (['a', 'b', 'c', 'd', 'e'] as $entry) { $result = (yield $entry); echo " {$entry} = {$result}".PHP_EOL; } }; $generator = $factory(); foreach ($generator as $item) { echo "value: {$item}".PHP_EOL; $generator->send($item.'+'); } <?php ``` Resulted in this output: ``` value: a a = a+ b = value: c c = c+ d = value: e e = e+ ``` But I expected this output instead: ``` value: a a = a+ value: b b = b+ value: c c = c+ value: d d = d+ value: e e = e+ ``` ### PHP Version 7.4.0 - 7.4.33, 8.0.1 - 8.0.25, 8.1.0 - 8.1.12, 8.2rc1 - rc3 ### Operating System _No response_

« previous php.bugs (#242764) next »