|  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
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.
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: Sun Jun 16 12:01:28 2024 UTC