News Feed
Jobs Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

The PHP.cc:
PHP 5.5 Generators
July 10, 2013 @ 11:49:04

In this latest post to The PHP.cc's blog, Sebastian Bergmann talks about using a new feature in PHP - generators.

A generator is an interruptible function that returns a sequence of values (using the yield keyword) instead of a single value (using the return keyword). Two things happen when the yield statement of a generator function is executed: the argument of the yield statement is yielded and the execution of the generator function is suspended. The execution of the generator function is resumed when the next value is requested.

He starts with a simple example, showing a basic foreach loop calling a generator to produce (yield) an incrementing number each time. He also provides a more "real world" use case - using generators as data providers for PHPUnit tests. His example generates a new "Address" object each time the provider is called with a bit of "randomized" information included.

0 comments voice your opinion now!
generators introduction phpunit data provider tutorial

Link: http://thephp.cc/viewpoints/blog/2013/07/php-5-5-generators

blog comments powered by Disqus

Similar Posts

php|architect: Using the PEAR Installer (Parts 1 & 2)

Arnold Daniels' Blog: Migrating from PHP4 to PHP5: A strategy for hosts

Developer Tutorials Blog: SimpleTest: Unit Testing for PHP

PHPMaster.com: Sending Email with Swift Mailer

SitePoint.com: Advanced PHPUnit Testing: Annotations and Mocking


Community Events











Don't see your event here?
Let us know!


package hack podcast facebook composer code release install unittest threedevsandamaybe component application opinion language overview security hhvm framework symfony2 introduction

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework