Skip to content

Instantly share code, notes, and snippets.

@dantleech
Created October 18, 2016 12:37
Show Gist options
  • Select an option

  • Save dantleech/82618e89521e85ffd484a67b72d5ea76 to your computer and use it in GitHub Desktop.

Select an option

Save dantleech/82618e89521e85ffd484a67b72d5ea76 to your computer and use it in GitHub Desktop.
<?php
class Collection implements \IteratorAggregate
{
private $foo;
private $bar;
private $collection;
public function __construct(\Traversable $collection)
{
$this->foo = 'bar';
$this->bar = 'foo';
$this->collection = $collection;
}
public function getIterator()
{
return new \ArrayIterator($this->collection);
}
}
$collection = new Collection(new \ArrayObject([
new \stdClass(), new \stdClass(), new stdClass()
]));
var_dump(next($collection));die();;
// "foo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment