php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79614 Nested 'yield from' duplicate first element
Submitted: 2020-05-20 02:22 UTC Modified: 2020-05-20 22:28 UTC
From: ponomarev at gmail dot com Assigned: cmb (profile)
Status: Duplicate Package: Scripting Engine problem
PHP Version: 7.4.6 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
35 - 6 = ?
Subscribe to this entry?

 
 [2020-05-20 02:22 UTC] ponomarev at gmail dot com
Description:
------------
See the example script. 

First element yielded twice if iterate over a generator that `yield from` another generator.

Test script:
---------------
https://3v4l.org/2ZQ8d

<?php

$arr = [1,2,3];

function a($x){
    yield from $x;
}


foreach(a(a($arr)) as $x){
    print_r($x);
}

Expected result:
----------------
123


Actual result:
--------------
1123

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-05-20 02:42 UTC] requinix@php.net
No doubt related to bug #78434.
 [2020-05-20 07:17 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Package: *General Issues +Package: Scripting Engine problem -Assigned To: +Assigned To: cmb
 [2020-05-20 07:17 UTC] cmb@php.net
Well, actually a duplicate of that bug.
 [2020-05-20 18:11 UTC] requinix@php.net
Duplicate? 78434 fixed an issue where the first generated item wasn't being yielded. This is an issue where the first generated item is being yielded too many times - and it started after 78434's fix landed in 7.4.6.
 [2020-05-20 18:25 UTC] ponomarev at gmail dot com
It seems to be duplicate of #79600
 [2020-05-20 18:26 UTC] requinix@php.net
Well spotted. The fix for bug #79600 will be in 7.4.7.
 [2020-05-20 22:28 UTC] cmb@php.net
Thanks for the correction! :)
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Nov 25 23:01:24 2020 UTC