Created
March 17, 2016 21:54
-
-
Save jpauli/85211102df1a17f22de5 to your computer and use it in GitHub Desktop.
Objects as Generators
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 | |
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