|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79657 "yield from" hangs when invalid value encountered
Submitted: 2020-05-31 17:09 UTC Modified: 2020-05-31 18:49 UTC
From: max dot tun at pm dot me Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 7.4.6 OS: Alpine Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: max dot tun at pm dot me
New email:
PHP Version: OS:


 [2020-05-31 17:09 UTC] max dot tun at pm dot me
Starting from PHP 7.4.6 (I've managed to reproduce on 7.4.7RC1 as well) "yield from" hangs when I try to unwrap generator into function arguments and an invalid value is encountered or an exception is thrown.

In the example provided this won't happen if the "get" function doesn't have arguments.
This also doesn't happen if I unwrap the generator into an array.
Also, works as expected if an error occurs on first iteration.

The script hangs on line #15 and CPU usage and memory consumption increases significantly, looks like there's an infinite loop.

Test script:

function throwException(): iterable
    throw new Exception();

function loop(): iterable
    $callbacks = [
        function () {
            yield 'first';
        function () {
            yield from throwException();

    foreach ($callbacks as $callback) {
        yield from $callback();

function get(string $first, int $second): array
    return [];


Expected result:
Either this if I throw an exception:

Fatal error: Uncaught Exception in test.php:5
Stack trace:
#0 test.php(15): throwException()
#1 test.php(20): {closure}()
#2 test.php(29): loop()
#3 {main}
  thrown in test.php on line 5

Or the following if an invalid value is being used to yield from:

Fatal error: Uncaught Error: Can use "yield from" only with arrays and Traversables in test.php:15
Stack trace:
#0 test.php(20): {closure}()
#1 test.php(29): loop()
#2 {main}
  thrown in test.php on line 15


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-05-31 18:49 UTC]
-Status: Open +Status: Verified -Package: *General Issues +Package: Scripting Engine problem
 [2020-06-08 09:32 UTC]
Automatic comment on behalf of
Log: Fixed bug #79657
 [2020-06-08 09:32 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jun 21 18:01:31 2024 UTC