Bug #77433 [Opn]: iterator_to_array incorrect result when using yield from

From: Date: Wed, 09 Jan 2019 14:09:17 +0000
Subject: Bug #77433 [Opn]: iterator_to_array incorrect result when using yield from
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-218861@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77433&edit=1 ID: 77433 Updated by: salathe@php.net Reported by: jwurtz at jolicode dot com Summary: iterator_to_array incorrect result when using yield from Status: Open Type: Bug Package: Arrays related PHP Version: 7.1.25 Block user comment: N Private report: N New Comment: Be sure to set the $use_keys parameter of iterator_to_array() to false, since the keys overlap (try foreach and printing the keys). Previous Comments: ------------------------------------------------------------------------ [2019-01-09 14:00:30] jwurtz at jolicode dot com Description: ------------ When using iterator_to_array on a function that return a \Generator, if this function use both yield and yield from it will only put values of the yield from expression. Test script: --------------- <?php function yield1() { yield 'foo'; } function yield2() { yield 'bar'; yield from yield1(); } // Will only display foo var_dump(iterator_to_array(yield2())); // will correctly display each value foreach (yield2() as $data) { var_dump($data); } Expected result: ---------------- It should create an array with all values and not only the one from the yield from expression. Actual result: -------------- Create an array only on the yield from expression ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77433&edit=1

« previous php.bugs (#218861) next »