|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69419 Returning compatible sub generator produces a warning
Submitted: 2015-04-10 13:02 UTC Modified: 2015-04-10 16:07 UTC
From: elliotlevin at hotmail dot com Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: master-Git-2015-04-10 (Git) OS:
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: elliotlevin at hotmail dot com
New email:
PHP Version: OS:


 [2015-04-10 13:02 UTC] elliotlevin at hotmail dot com
When generators were implemented, a generator function could return another generator even if it was a return by reference generator.

In PHP7 this now produces a warning because it is not a variable.


Test script:

function & genRefInner() {
    $var = 1;
    yield $var;

function & genRefOuter() {
    return genRefInner();

foreach(genRefOuter() as $i) {


Expected result:

Actual result:
Notice: Only variable references should be returned by reference in /in/sFR11 on line 9


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-04-10 14:25 UTC]
-Assigned To: +Assigned To: nikic
 [2015-04-10 15:33 UTC]
The behavior in PHP 7 is correct, I'll fix it to throw a strict standards notice in 5.x as well.
 [2015-04-10 16:07 UTC]
Another interesting case I didn't consider before is this:


class A {
    public function &gen() { yield; }
class B extends A {
    public function gen() { yield; }


Currently this throws the usual LSP strict standards notice, because by-reference returns are covariant.

Intuitively this seem correct to me as well, as you can iterate a by-ref generator by-val, but can't iterate a by-val generator by-ref.
 [2015-04-14 14:39 UTC]
Automatic comment on behalf of nikic
Log: Fixed bug #69419
 [2015-04-14 14:39 UTC]
-Status: Assigned +Status: Closed
 [2015-04-14 14:53 UTC]
I've split the inheritance issue into another bug:
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Mar 22 17:03:43 2023 UTC