php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72692 Bad behaviour of AppendIterator with Empty Generator
Submitted: 2016-07-28 05:09 UTC Modified: 2016-07-28 23:59 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: pierrick@php.net Assigned:
Status: Open Package: SPL related
PHP Version: 5.6.24 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2016-07-28 05:09 UTC] pierrick@php.net
Description:
------------
When giving an new empty generator, AppendIterator will directly throw an Exception "Cannot traverse an already closed generator" even if the given generator is new.

Test script:
---------------
<?php

function createEmptyGen() { if(false) { yield 1; } }
$gen = createEmptyGen();

$ai = new AppendIterator();
$ai->append($gen);
var_dump(iterator_to_array($gen));


Expected result:
----------------
array(0) {
}


Actual result:
--------------
Fatal error: Uncaught Exception: Cannot traverse an already closed generator in /home/pierrick/php-src/github/foo.php:14
Stack trace:
#0 /home/pierrick/php-src/github/foo.php(14): iterator_to_array(Object(Generator))
#1 {main}
  thrown in /home/pierrick/php-src/github/foo.php on line 14


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-28 23:59 UTC] nikic@php.net
Related: Bug #71436
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC