Skip to content

Instantly share code, notes, and snippets.

@jpauli
Created March 17, 2016 21:54
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 jpauli/85211102df1a17f22de5 to your computer and use it in GitHub Desktop.
Save jpauli/85211102df1a17f22de5 to your computer and use it in GitHub Desktop.
Objects as Generators
<?php
class Foo
{
public function __invoke($arg)
{
yield $arg;
}
}
$f = new Foo;
foreach ($f('foo') as $v) {
echo $v, "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment