|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #71252 Yield from by reference is not supported
Submitted: 2015-12-30 23:24 UTC Modified: 2021-09-22 12:07 UTC
Avg. Score:3.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: 7.0Git-2015-12-30 (Git) OS:
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:
New email:
PHP Version: OS:


 [2015-12-30 23:24 UTC]
When "yield from" was implemented, we did not consider how it interacts with yield-by-reference. Right now it is simply ignored and "yield from" yields all values by-value.

Likely this is not the expected or intended behavior. Instead "yield from" in a by-reference generator should yield array values and values from by-reference generators by-reference. "yield from" should generate an error for iterators (and generators) that do not support by-reference iteration.

Test script:
function &gen(array $array) {
    yield from $array;

$array = [1, 2, 3];
foreach (gen($array) as &$v) {
    $v += 1;

Expected result:
array(3) {

Actual result:
array(3) {


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-22 12:07 UTC]
-Summary: yield from ignores yield-by-reference +Summary: Yield from by reference is not supported -Type: Bug +Type: Documentation Problem
 [2021-09-22 12:07 UTC]
As of PHP 7.0.4 this is forbidden[1].  When looking at the
respective commit message[2] and the now long standing behavior,
it might be best to just document the behavior.

[1] <>
[2] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 05:01:27 2024 UTC