php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79616 Wrong behavior of Generator close when nesting "yield from"
Submitted: 2020-05-21 10:33 UTC Modified: 2020-05-21 10:37 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: jeremy at derusse dot com Assigned:
Status: Duplicate Package: Unknown/Other Function
PHP Version: 7.4.6 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jeremy at derusse dot com
New email:
PHP Version: OS:

 

 [2020-05-21 10:33 UTC] jeremy at derusse dot com
Description:
------------
Since php 7.4.6, When nesting several `yield from`, the `\Generator::valid` methods return true while the Generator stay open after the last item. (calling `Generator::valid` return once true after the last item.

Test script:
---------------
<?php

function foo()
{
    yield from ['foo', 'bar'];
}

function bar()
{
    yield from foo();
}

function countGenerator($generator)
{
    for ($count = 0; $generator->valid(); $generator->next()) {
        ++$count;
    }

    return $count;
}

var_dump(countGenerator(foo()));
var_dump(countGenerator(bar()));


Expected result:
----------------
int(2)
int(2)


Actual result:
--------------
int(2)
int(3)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-05-21 10:37 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2020-05-21 10:37 UTC] nikic@php.net
Duplicate of bug #79600.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Oct 22 10:01:24 2020 UTC