Created
March 11, 2015 15:01
-
-
Save m6w6/568dec3eac8a31d3b277 to your computer and use it in GitHub Desktop.
cake/Collection bug with generators and iterators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$gen = function() { | |
yield 1; | |
}; | |
$iter = new IteratorIterator($gen()); | |
$ngen = $iter->getInnerIterator(); | |
class ReplaceIterator extends IteratorIterator | |
{ | |
private $cb; | |
function __construct($iter, $cb) { | |
parent::__construct($iter); | |
$this->cb = $cb; | |
} | |
function current() { | |
$cb = $this->cb; | |
return $cb(parent::current()); | |
} | |
} | |
$filter = new ReplaceIterator($ngen, function($a){ return $a; }); | |
iterator_to_array($filter, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment