Skip to content

Instantly share code, notes, and snippets.

@m6w6
Created March 11, 2015 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m6w6/568dec3eac8a31d3b277 to your computer and use it in GitHub Desktop.
Save m6w6/568dec3eac8a31d3b277 to your computer and use it in GitHub Desktop.
cake/Collection bug with generators and iterators
<?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