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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 11:01:34 2024 UTC