Generators: All About the Yield

Generators: All About the Yield

Generators are a relatively unexplored feature of PHP. Coming about in PHP 5.5, Generators provide for the ability to write Iterator style code without a lot of upfront work. In addition to that Generators provide for some amazing abilities to write coroutines in PHP that we previously didn’t have. Generators are at their core a tool to enable us to write code that can solve entire classes of problems that beforehand would have been exceedingly hard to do before hand. Perhaps most importantly, generators are fun to explore.