php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67631 Yield command doens't work
Submitted: 2014-07-16 12:37 UTC Modified: 2014-07-16 14:13 UTC
From: lferro9000 at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.5.14 OS: MacOSx
Private report: No CVE-ID: None
 [2014-07-16 12:37 UTC] lferro9000 at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/language.generators.syntax
---
The Yield command which has the syntax:

yield $var;

In it's basic form doesn't work and issues on CLI the following error:

Parse error: parse error in test.php on line 7

Test script:
---------------
Test script is the example posted on the generators page:

<?php
function gen_one_to_three() {
    for ($i = 1; $i <= 3; $i++) {
        // Note that $i is preserved between yields.
        yield $i;
    }
}

$generator = gen_one_to_three();
foreach ($generator as $value) {
    echo "$value\n";
}

Expected result:
----------------
The yield command should work as documented.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-16 12:38 UTC] lferro9000 at gmail dot com
Line 5 i mean (the line with the yield statement).
 [2014-07-16 12:56 UTC] lferro9000 at gmail dot com
-Status: Open +Status: Closed
 [2014-07-16 12:56 UTC] lferro9000 at gmail dot com
Issue with multiple versions of PHP on the computer.
 [2014-07-16 14:13 UTC] rasmus@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 07 08:01:32 2024 UTC