Bug #80917 [Com]: LimitIterator does not end at count

From: Date: Mon, 29 Mar 2021 20:11:29 +0000
Subject: Bug #80917 [Com]: LimitIterator does not end at count
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233054@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80917&edit=1 ID: 80917 Comment by: alexandreparent_dev at outlook dot com Reported by: alexandreparent_dev at outlook dot com Summary: LimitIterator does not end at count Status: Open Type: Bug Package: SPL related Operating System: All PHP Version: Irrelevant Block user comment: N Private report: N New Comment: I inverted actual and expected results. Previous Comments: ------------------------------------------------------------------------ [2021-03-29 20:08:53] alexandreparent_dev at outlook dot com Description: ------------ LimitIterator will try to iterate beyond $count. If its inner iterator never yield another item nor return, the LimitIterator will not limit at the expected count. Test script: --------------- <?php function generator(): iterable { $count = 0; while (true) { yield $count++; echo 'Yielded: ', $count - 1, \PHP_EOL; if ($count > 2) { while(true); } } } foreach (new \LimitIterator($generator(), 0, 3) as $count) { echo 'Iterating: ', $count, \PHP_EOL; } Expected result: ---------------- Iterating: 0 Yielded: 0 Iterating: 1 Yielded: 1 Iterating: 2 Yielded: 2 // Hanging here Actual result: -------------- Iterating: 0 Yielded: 0 Iterating: 1 Yielded: 1 Iterating: 2 // Exiting here ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80917&edit=1

« previous php.bugs (#233054) next »