php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65092 Neither errors nor result with generators and anonymous functions
Submitted: 2013-06-21 21:58 UTC Modified: 2013-06-22 08:12 UTC
From: michael at squiloople dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.5.0 OS: Windows Vista SP2
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: michael at squiloople dot com
New email:
PHP Version: OS:

 

 [2013-06-21 21:58 UTC] michael at squiloople dot com
Description:
------------
When using generators with an anonymous function neither an error nor the expected 
result are shown.

Test script:
---------------
  foreach (function ()
  {

    for ($i = 1; $i <= 10; ++$i)
    {
      yield $i => $i;
    }

  } as $key => $value)
  {
    echo $key . ': ' . $value . '<br>';
  }

Expected result:
----------------
Either:

1: 1
2: 2
3: 3
4: 4
5: 5
6: 6
7: 7
8: 8
9: 9
10: 10

Or an error of some sort.

Actual result:
--------------
[neither result nor error]

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-22 08:12 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2013-06-22 08:12 UTC] nikic@php.net
You are trying to iterate over a closure, so you get an empty loop (closures have no properties).

If you want to iterate over the generator you need to call the closure first.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat May 03 16:01:29 2025 UTC